Skip to content

Instantly share code, notes, and snippets.

@basekays
Created January 30, 2017 06:04
Show Gist options
  • Select an option

  • Save basekays/97d7ca8bd00a3442cc7bd41caa8bfbb9 to your computer and use it in GitHub Desktop.

Select an option

Save basekays/97d7ca8bd00a3442cc7bd41caa8bfbb9 to your computer and use it in GitHub Desktop.
var getElementsByClassName = function(className, element) {
//creating resultArr to be returned
var resultArr = [];
var element = element || document.body;
var targetNodes = element.childNodes;
if (element.classList) {
if (element.classList.contains(className)) {
resultArr.push(element);
}
if (children.length > 0) {
for(var i = 0; i < targetNodes.length; i++) {
resultArr = resultArr.concat(getElementsByClassName(className, targetNodes[i]));
}
}
return resultArr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment