Created
February 10, 2019 17:02
-
-
Save bobbykjack/ea85abfb66e419ffd45564abd5bba3e7 to your computer and use it in GitHub Desktop.
Iterative approach to walking a DOM tree in javascript
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
| function visit_nodes_iterative(node) { | |
| node = node || document; | |
| do | |
| { | |
| /* Do something with node here */ | |
| node = node.firstChild || node.nextSibling || function() { | |
| while ((node = node.parentNode) && !node.nextSibling); | |
| return node ? node.nextSibling : null; | |
| }(); | |
| } | |
| while (node); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment