Skip to content

Instantly share code, notes, and snippets.

@monolithed
Created June 17, 2013 10:52
Show Gist options
  • Save monolithed/5796107 to your computer and use it in GitHub Desktop.
Save monolithed/5796107 to your computer and use it in GitHub Desktop.
var getElementsByClassName = function(name) {
if(document.getElementsByClassName)
return document.getElementsByClassName(name);
else if(document.querySelectorAll)
return document.querySelectorAll('.' + name);
else {
var list = document.getElementsByTagName('*'), i = list.length,
array = name.split(/\s+/), result = [];
while(i--) {
if(list[i].className.search('\\b' + array + '\\b') != -1)
result.push(list[i]);
}
return result;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment