Created
August 16, 2011 14:35
-
-
Save joshje/1149224 to your computer and use it in GitHub Desktop.
Cross Browser CSS Selector Support Detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function supports(prop) { | |
var div = document.createElement('div'), | |
vendors = ['Khtml','Ms','O','Moz','Webkit'], | |
len = vendors.length; | |
if (prop in div.style) return true; | |
var prop = prop.replace(/^[a-z]/, function(val) { | |
return val.toUpperCase(); | |
}); | |
while(len--) { | |
if ( vendors[len] + prop in div.style ) return true; | |
} | |
return false; | |
} | |
// Usage (JS styles are camelCase): | |
// document.getElementsByTagName('html')[0].className += supports('transitionProperty')? ' transitions' : ' no-transitions'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment