Created
January 30, 2017 06:04
-
-
Save basekays/97d7ca8bd00a3442cc7bd41caa8bfbb9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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