Skip to content

Instantly share code, notes, and snippets.

@zdfs
Last active December 17, 2015 10:29
Show Gist options
  • Save zdfs/5595014 to your computer and use it in GitHub Desktop.
Save zdfs/5595014 to your computer and use it in GitHub Desktop.
Polyfill for getElementsByClassName
function findElementsByClass(className) {
var result = [],
elements = document.getElementsByTagName("*"),
classes;
for (var i = 0, ilen = elements.length; i < ilen; i+=1) {
if (elements[i].className !== "") {
classes = elements[i].className.split(" ");
for (j = 0, jlen = classes.length; j < jlen; j+=1) {
if (classes[j] === className) {
result.push(elements[i]);
break;
}
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment