Skip to content

Instantly share code, notes, and snippets.

@desandro
Created January 24, 2013 15:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desandro/4623257 to your computer and use it in GitHub Desktop.
Save desandro/4623257 to your computer and use it in GitHub Desktop.
getStyleProperty
/*!
* getStyleProperty by kangax
* http://perfectionkills.com/feature-testing-css-properties/
*/
/*jshint browser: true, strict: true, undef: true */
( function( window ) {
'use strict';
var prefixes = 'Webkit Moz ms Ms O'.split(' ');
var docElemStyle = document.documentElement.style;
function getStyleProperty( propName ) {
// test standard property first
if ( typeof docElemStyle[ propName ] === 'string' ) {
return propName;
}
// capitalize
propName = propName.charAt(0).toUpperCase() + propName.slice(1);
// test vendor specific properties
var prefixed;
for ( var i=0, len = prefixes.length; i < len; i++ ) {
prefixed = prefixes[i] + propName;
if ( typeof docElemStyle[ prefixed ] === 'string' ) {
return prefixed;
}
}
}
// publicize
window.getStyleProperty = getStyleProperty;
})( window );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment