Skip to content

Instantly share code, notes, and snippets.

@jehoshua02
Created September 5, 2014 01:04
Show Gist options
  • Save jehoshua02/d33892df58a95244cf5c to your computer and use it in GitHub Desktop.
Save jehoshua02/d33892df58a95244cf5c to your computer and use it in GitHub Desktop.
Check if a style property is supported.
var styleSupported = (function () {
var supported = [];
var check = function (property) {
var body = document.body || document.documentElement;
var style = body.style;
// check for standard
if (typeof style[property] == 'string') { return true; }
// check for vendor specific
var vendors = ['Moz', 'webkit', 'Webkit', 'Khtml', 'O', 'ms'];
property = property.charAt(0).toUpperCase() + property.substr(1);
for (var i = 0; i < vendors.length; i++) {
var vendorProperty = vendors[i];
if (typeof style[vendorProperty] == 'string') { return true; }
}
return false;
};
return function (property) {
if (supported[property] === undefined) {
supported[property] = check(property);
}
return supported[property];
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment