Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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