Last active
September 12, 2020 20:09
-
-
Save johntran/9ffd7afd988003b3844e to your computer and use it in GitHub Desktop.
walking the DOM from Douglas Crockford, JavaScript: The Good Parts, p. 36
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
/** Define a walk_the_DOM function that visits every | |
* node of the tree in HTML source order, starting | |
* from some given node. It invokes a function, | |
* passing it each node in turn. walk_the_DOM calls | |
* itself to process each of the child nodes. | |
*/ | |
var walk_the_DOM = function walk(node, callback) { | |
callback(node); | |
node = node.firstChild; | |
while (node) { | |
walk(node, callback); | |
node = node.nextSibling; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment