Skip to content

Instantly share code, notes, and snippets.

@oslego
Last active August 29, 2015 13:57
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 oslego/9878181 to your computer and use it in GitHub Desktop.
Save oslego/9878181 to your computer and use it in GitHub Desktop.
Converts a CSS property name to its DOM form. Removes dashes and upperacases the char following the dash.
/*
Takes a CSS property name string and returns its DOM notation.
@example: shape-inside -> shapeInside
@example: -webkit-shape-inside -> webkitShapeInside
@param {String} str CSS property name, possibly hyphenated.
@return {String}
*/
function getDOMCSSProperty(str){
// remove first dash if the property is prefixed
str = (str.indexOf("-") === 0) ? str.substr(1) : str;
// remove the dash and uppercase the char after the dash
return str.replace(/-(\S)/g, function(str, group){
return group.toUpperCase();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment