Posted By

scott2b on 09/16/09


Tagged

DOM


Versions (?)

walking the DOM


 / Published in: JavaScript
 

from Douglas Crockford, JavaScript: The Good Parts, 1st ed., p. 36

  1. // Define a walk_the_DOM function that visits every
  2. // node of the tree in HTML source order, starting
  3. // from some given node. It invokes a function,
  4. // passing it each node in turn. walk_the_DOM calls
  5. // itself to process each of the child nodes.
  6. var walk_the_DOM = function walk(node, func) {
  7. func(node);
  8. node = node.firstChild;
  9. while (node) {
  10. walk(node, func);
  11. node = node.nextSibling;
  12. }
  13. };

Report this snippet  

You need to login to post a comment.