Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.