Skip to content

Instantly share code, notes, and snippets.

@robabby
Created November 6, 2015 13:13
Show Gist options
  • Select an option

  • Save robabby/5b7b42e4cc34317d8d70 to your computer and use it in GitHub Desktop.

Select an option

Save robabby/5b7b42e4cc34317d8d70 to your computer and use it in GitHub Desktop.
A simple function to start walking the DOM written in vanilla JS
function walkTheDOM(node) {
if (node.nodeType == 1) {
//console.log(node.tagName);
node = node.firstChild;
while (node) {
theDOMElementWalker(node);
node = node.nextSibling;
}
}
}
var element = document.getElementByTagName('body');
console.log(walkTheDOM(element));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment