Skip to content

Instantly share code, notes, and snippets.

@oslego
Created July 17, 2009 07: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/148938 to your computer and use it in GitHub Desktop.
Save oslego/148938 to your computer and use it in GitHub Desktop.
Detect browser CSS capabilities by looking for DOM property references
/**
* @author Razvan Caliman, razvan.caliman@gmail.com
*/
/**
* wrapper for browser sniffing / capabilities check methods
*/
var browser = {};
/**
* Check if the browser has a CSS property and is capable of using it via DOM scripting
*
* @param {String} propetyName
* name of the css property to check for in the browser
*
* @return {Boolean}
*/
browser.hasCssProperty = function(propertyName){
//look for a dashed CSS property like max-height
var pName = propertyName.split("-");
//convert dashed CSS properties (max-height) to camelCase DOM properties (maxHeight)
if (pName.length > 1){
//start building the DOM property name
propertyName = pName[0];
for (var i=1; i<pName.length; i++){
//Uppercase the first letter
propertyName += pName[i].substr(0,1).toUpperCase();
//Concat the rest of the word, without the first letter
propertyName += pName[i].substr(1);
}
}
var testEl = document.createElement('div');
return (testEl.style[propertyName] !== undefined)
? true
: false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment