Last active
October 15, 2015 22:26
-
-
Save simplesthing/e269d5cfbbd156cca78b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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