Last active
December 17, 2015 10:29
-
-
Save zdfs/5595014 to your computer and use it in GitHub Desktop.
Polyfill for getElementsByClassName
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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