Skip to content

Instantly share code, notes, and snippets.

@C-Rodg
Created November 4, 2016 01:27
Show Gist options
  • Save C-Rodg/12c3511b81fbaf17de68d979bf1b5271 to your computer and use it in GitHub Desktop.
Save C-Rodg/12c3511b81fbaf17de68d979bf1b5271 to your computer and use it in GitHub Desktop.
A recursive DOM traversal method for finding a specific node.
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