Skip to content

Instantly share code, notes, and snippets.

@0xnbk
Created November 16, 2010 09:15
Show Gist options
  • Save 0xnbk/701606 to your computer and use it in GitHub Desktop.
Save 0xnbk/701606 to your computer and use it in GitHub Desktop.
Test CSS3 Support with JS
var supports = (function() {
var div = document.createElement('div'),
vendors = 'Khtml Ms O Moz Webkit'.split(' '),
len = vendors.length;
return function(prop) {
if ( prop in div.style ) return true;
prop = prop.replace(/^[a-z]/, function(val) {
return val.toUpperCase();
});
while(len--) {
if ( vendors[len] + prop in div.style ) {
// browser supports box-shadow. Do what you need.
// Or use a bang (!) to test if the browser doesn't.
return true;
}
}
return false;
};
})();
if ( supports('textShadow') ) {
document.documentElement.className += ' textShadow';
}
@0xnbk
Copy link
Author

0xnbk commented Nov 16, 2010

This function will test whether or not the browser supports a specified CSS3 property, like "border-radius."

Note that, when passing the property, omit the dash. So, instead of "border-radius," pass "borderRadius" (or "BorderRadius").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment