find number of nodes between two elements with jquery?
<p>I'm having a little trouble figuring out a fast way to accomplish a (seemingly) simple task.  Say I have the following html:</p>

<pre><code>&lt;ul&gt;
  &lt;li&gt;One&lt;/li&gt;
  &lt;li&gt;Two&lt;/li&gt;
  &lt;li id='parent'&gt;
    &lt;ul&gt;
      &lt;li&gt;Three&lt;/li&gt;
      &lt;li&gt;
        &lt;ul&gt;
          &lt;li&gt;Four&lt;/li&gt;
          &lt;li id='child'&gt;Five&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;Six&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>And have the following two elements:</p>

<pre><code>var child = $("#child");
var parent = $("#parent");
</code></pre>

<p>In this example, it's clear that:</p>

<pre><code>child.parent().parent().parent().parent();
</code></pre>

<p>will be the same node as 'parent'.  But the list I'm traversing is variable size, so I need to find a way to find out how many '.parent()'s I'll need to go through to get to that parent node.  I always know where child and parent are, I just don't know how many 'layers' there are in between.</p>

<p>Is there any built in jQuery method to do something like this, or is my best bet a recursive function that gets the parent, checks if the parent is my desired node, and if not calls itself on its parent?</p>

<p>Edit:  I may not have explained myself clearly enough.  My problem isn't getting TO the parent, my problem is finding out how many nodes are between the child and parent.  In my example above, there are 3 nodes in between child and parent.  That's the data I need to find.</p>
