Skip to content

Instantly share code, notes, and snippets.

@mattjburrows
Created March 13, 2014 16:03
Show Gist options
  • Select an option

  • Save mattjburrows/9531251 to your computer and use it in GitHub Desktop.

Select an option

Save mattjburrows/9531251 to your computer and use it in GitHub Desktop.
Return a matching prefix from either an array or object literal. If non match return false.
function getPrefix(prefixes) {
var div = document.createElement('div');
// Check to see if we are dealing with an array.
if(Object.prototype.toString.call(prefixes) === '[object Array]') {
var max = prefixes.length;
while(max--) {
if(prefixes[max] in div.style) {
return prefixes[max];
}
}
}
// Else we'll assume it is an object.
else {
for(prefix in prefixes) {
if(prefix in div.style) {
return prefixes[prefix];
}
}
}
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment