Skip to content

Instantly share code, notes, and snippets.

@dmjio
Created August 17, 2011 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmjio/1152855 to your computer and use it in GitHub Desktop.
Save dmjio/1152855 to your computer and use it in GitHub Desktop.
Walking the DOM Recursively
function walkTheDOM(node, F)
{
F(node);
node = node.firstChild;
while (node)
{
walkTheDom(node, F);
node = node.nextSibling; //Changes state here, destroying node
}
}
walkTheDOM(document.getElementById("theBody"),
function(node)
{
alert(node.nodeName + "," + node.nodeValue);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment