Skip to content

Instantly share code, notes, and snippets.

@tbusser
Created February 3, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbusser/118679c67e4ebc75b8e9 to your computer and use it in GitHub Desktop.
Save tbusser/118679c67e4ebc75b8e9 to your computer and use it in GitHub Desktop.
Set prefixed property
var vendors = ['webkit', 'moz', 'ms'];
/**
* This method sets a CSS property. It will set the standard property as
* well as vender prefixed versions of the property.
*
* @param {HTMLElement} element The element whose property to set
* @param {string} property The unprefixed name of the property
* @param {string} value The value to assign to the property
*/
function setPrefixedProperty(element, property, value) {
// Capitalize the first letter in the string
var capitalizedProperty = property[0].toUpperCase() + property.slice(1);
// Loop over the vendors and set the prefixex property
for (var index = 0, ubound = vendors.length; index < ubound; index++) {
element.style[vendors[index] + capitalizedProperty] = value;
}
// Set the standard property
element.style[property] = value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment