/ Published in: JavaScript

from Douglas Crockford, JavaScript: The Good Parts, 1st ed., p. 36
Expand |
Embed | Plain Text
// 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; } };
You need to login to post a comment.