Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Crockfordian walk the dom
  2. var walkTheDOM = function walk(node, func) {
  3.     func(node);
  4.     node = node.firstChild;
  5.     while (node) {
  6.         walk(node, func);
  7.         node = node.nextSibling;
  8.     }
  9. };
  10. var getTextNodes = function(node,func){
  11.     walkTheDOM(document.body,function(node){
  12.         if(node.nodeType==3){
  13.             func(node);
  14.         }
  15.     });
  16. };
  17. getTextNodes(document.body,function(node){
  18.     console.log(node.nodeValue);
  19. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement