Skip to content

Instantly share code, notes, and snippets.

@simplesthing
Last active October 15, 2015 22:26
Show Gist options
  • Save simplesthing/e269d5cfbbd156cca78b to your computer and use it in GitHub Desktop.
Save simplesthing/e269d5cfbbd156cca78b to your computer and use it in GitHub Desktop.
<script>
var steps = [];
function up(node){
if(node.previousSibling){
steps.push('nextSibling');
node = node.previousSibling;
up(node);
return;
}
if(node.parentNode){
steps.push('firstChild');
node = node.parentNode;
up(node);
return;
}
down();
}
function down(){
var node = document;
var walk = steps.reverse();
walk.forEach(function(step){
node = node[step];
});
node.style.background = 'red';
console.log(node);
}
var start = document.querySelector('#node');
up(start);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment