Last active
December 15, 2015 15:08
-
-
Save julsfelic/5279187 to your computer and use it in GitHub Desktop.
getElementsByClassName function. Provides a fallback for legacy browsers that do not support the native HTML5 DOM method.
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 getElementsByClassName(node, className) { | |
if (node.getElementsByClassName) { | |
return node.getElementsByClassName(className); | |
} else { | |
var results = []; | |
var elems = node.getElementsByTagName("*"); | |
for (var i = 0, len = elems.length; i < len; i++) { | |
if (elems[i].className.indexOf(className) != -1) { | |
results.push(elem[i]); | |
} | |
} | |
return results; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment