Skip to content

Instantly share code, notes, and snippets.

@mmckegg
Created October 15, 2013 00:42
Show Gist options
  • Save mmckegg/6984802 to your computer and use it in GitHub Desktop.
Save mmckegg/6984802 to your computer and use it in GitHub Desktop.
function walkDom(rootNode, iterator){
var currentNode = rootNode.firstChild
while (currentNode){
iterator(currentNode)
if (currentNode.firstChild){
currentNode = currentNode.firstChild
} else {
while (currentNode && !currentNode.nextSibling){
if (currentNode !== rootNode) {
currentNode = currentNode.parentNode
} else {
currentNode = null
}
}
currentNode = currentNode && currentNode.nextSibling
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment