title: Traversing list elements with jquery
body: <p>I'm building a micro site at the moment and I have a problem. I want to scroll to the different list elements by clicking on my menu. This is working fine. But the problem is, by using the list index to traverse to the second or third element of mainmenu, its only working fine in the first menu because the index of the second menu is starting with 3 by adding to the first one. So <code>.mainmenu.children</code> is the wrong call, but i don't know the right one.</p>
  
  <p>So the question is, how can I select a list index by his parent menu only? I don't want to use three different ids because the menu should be dynamic. </p>
  
  <p>hopefully someone can help me. </p>
  
  <p>best regards</p>
  
  <p>h-man24</p>
  
  <pre><code>$('.mainmenu').children('li').click(function(){     
      var myIndex = $('.mainmenu li').index(this);
      alert(myIndex + "  " + myPosition);
      var myPosition = $('#page &gt; li').eq(myIndex).offset().top;
      $('html, body').animate({scrollTop:myPosition, duration:500, easing:'easeInOutCirc'});  
  });
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;ul&gt;
  &lt;li&gt;
      &lt;div&gt;
      &lt;ul class="mainmenu"&gt;
      &lt;li&gt;Link to 1&lt;/li&gt; (index 0)
      &lt;li&gt;Link to 2&lt;/li&gt; (index 1)
      &lt;li&gt;Link to 3&lt;/li&gt; (index 2)
      &lt;/ul&gt;
      &lt;div&gt;Content 1&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
      &lt;div&gt;
      &lt;ul class="mainmenu"&gt;
      &lt;li&gt;Link to 1&lt;/li&gt; (index 3, should be 0)
      &lt;li&gt;Link to 2&lt;/li&gt; (index 4, should be 1)
      &lt;li&gt;Link to 3&lt;/li&gt; ....
      &lt;/ul&gt;
      &lt;div&gt;Content 2&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
      &lt;div&gt;
      &lt;ul class="mainmenu"&gt; 
      &lt;li&gt;Link to 1&lt;/li&gt;
      &lt;li&gt;Link to 2&lt;/li&gt;
      &lt;li&gt;Link to 3&lt;/li&gt;
      &lt;/ul&gt;
      &lt;div&gt;Content 3&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/li&gt;
  </code></pre>