Created
November 26, 2014 16:37
-
-
Save mgechev/5fbeca3627fef7bad0de 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
function getElementsByTagName(root, tagName) { | |
tagName = tagName.toUpperCase(); | |
var stack = [root], | |
result = [], | |
current, node; | |
while (stack.length) { | |
current = stack.pop(); | |
for (var i = 0; i < current.children.length; i += 1) { | |
node = current.children[i]; | |
if (node.tagName.toUpperCase() === tagName) { | |
result.push(node); | |
} | |
stack.push(node); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment