Skip to content

Instantly share code, notes, and snippets.

@mnewt
Created October 23, 2012 04:45
Show Gist options
  • Save mnewt/3936747 to your computer and use it in GitHub Desktop.
Save mnewt/3936747 to your computer and use it in GitHub Desktop.
walk the dom
// 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, func) {
func(node);
node = node.firstChild;
while (node) {
walk(node, func);
node = node.nextSibling;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment