how do i traverse ancestors with jQuery?
<p>How do I traverse ancestors with jQuery?</p>

<p>The current code is getting stuck in a recursive loop:</p>

<p>HTML:</p>

<pre><code>&lt;html&gt;
    &lt;body&gt;
        &lt;div&gt;
            &lt;ul&gt;
                &lt;li&gt;&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>JS:</p>

<pre><code>function traverse($node){
  while ( $node.get(0) !== $("html").get(0) ) {
    console.log($node);
    traverse($node.parent());
  }

}

//traverse($("ul li"));
</code></pre>

<p>To observe the problem, un-comment the last line, but be warned that it may freeze your browser.</p>

<p>The same on JSFiddle: <a href="http://jsfiddle.net/WpvJN/1/" rel="nofollow">http://jsfiddle.net/WpvJN/1/</a>   </p>
