Last active
January 4, 2017 21:41
-
-
Save jasonwilliams/ce6d9815771c5d427519a3412fbd035a to your computer and use it in GitHub Desktop.
My attempt to find a DOM node using a recursive technique, you have to use a recursive pattern
This file contains 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 findDomNodeById(root, id, result) { | |
var result = result || []; | |
// set base case | |
if (root.id === id) { | |
result.push(root); | |
} | |
if (root.childNodes.length) { | |
for (let i = 0; i < root.childNodes.length; i++) { | |
findDomNodeById(root.childNodes[i], id, result); | |
} | |
} | |
return result[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment