Created
November 4, 2016 01:27
-
-
Save C-Rodg/12c3511b81fbaf17de68d979bf1b5271 to your computer and use it in GitHub Desktop.
A recursive DOM traversal method for finding a specific node.
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 traverse(node, current) { | |
if(node.isEqualNode(current)){ | |
return current; | |
} else { | |
let el = null; | |
for(let i = 0; !el && i < current.children.length; i++){ | |
el = traverse(node, current.children[i]); | |
} | |
return el; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment