Implementing an algorithm that walks the DOM without recursion
I know you are doing this as an exercise, and personally I like the recursive function. But just as an alternative, there is also the much forgotten TreeWalker API.


  Browser compatibility
  
  Supported by IE9+, FF2+, Chrome 1+, Safari 3+, Opera 9+


Javascript

var treeWalker = document.createTreeWalker(document.getElementById("list"), NodeFilter.SHOW_ALL, {
    acceptNode: function (node) {
        return NodeFilter.FILTER_ACCEPT;
    }
}, false);

do {
    console.log(treeWalker.currentNode);
} while (treeWalker.nextNode());


On jsfiddle