Skip to content

Instantly share code, notes, and snippets.

@julsfelic
Last active December 15, 2015 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julsfelic/5279187 to your computer and use it in GitHub Desktop.
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.
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