Skip to content

Instantly share code, notes, and snippets.

@jasonwilliams
Last active January 4, 2017 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonwilliams/ce6d9815771c5d427519a3412fbd035a to your computer and use it in GitHub Desktop.
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
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