Created
February 3, 2015 13:19
-
-
Save tbusser/118679c67e4ebc75b8e9 to your computer and use it in GitHub Desktop.
Set prefixed property
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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