 <p><code>childNodes</code> only contains the direct children of the element--you need to recurse the <code>childNodes</code> of each node as well.</p> <p>I highly recommend that you use a framework like jQuery (http://jquery.com) to make the code simpler: <a href="http://jsfiddle.net/jDEhU/5/" rel="nofollow">http://jsfiddle.net/jDEhU/5/</a></p> <pre><code>$('#nav').delegate('li', 'click', function() { var self = $(e.target), //get a reference to the clicked element active = self.parents().andSelf() //select all li's that should be active .addClass('active'); //and activate them $('#nav .active').not(active).removeClass('active'); //deactivate others }); </code></pre>