Skip to content

Instantly share code, notes, and snippets.

@cgcardona
Last active February 19, 2023 17:46
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 cgcardona/ad5d44378dfc74fac77172bb8964ecab to your computer and use it in GitHub Desktop.
Save cgcardona/ad5d44378dfc74fac77172bb8964ecab to your computer and use it in GitHub Desktop.
Recursive function which allows us to go through the tree and visit all the nodes. From Douglas Crockford: An Inconvenient API - The Theory of the DOM @ 27:34 https://youtu.be/Y2Y0U-2qJMs?t=1654
function walkTheDOM(node, callback) {
callback(node)
node = node.firstChild
while (node) {
walkTheDOM(node, callback)
node = node.nextSibling
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment