Skip to content

Instantly share code, notes, and snippets.

@ingowennemaring
Created August 6, 2015 15:46
Show Gist options
  • Save ingowennemaring/c1d389068d80ea866479 to your computer and use it in GitHub Desktop.
Save ingowennemaring/c1d389068d80ea866479 to your computer and use it in GitHub Desktop.
Check if a browser supports a feature
function supports ( prop ) {
var div = document.createElement( 'div' ),
vendors = 'Khtml Ms O Moz Webkit'.split( ' ' ),
len = vendors.length;
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment