hello!

i have this (sample) html:

<ul id="menu1" class="mainmenu">
<li><a href="#" class="strataTrigger">item1</a></li>
<li><a href="#" class="strataTrigger">item2</a></li>
<li><a href="#" class="strataTrigger">item3</a></li>
</ul>

<ul id="menu2"  class="mainmenu">
<li><a href="#" class="strataTrigger">item1</a></li>
<li><a href="#" class="strataTrigger">item2</a></li>
<li><a href="# class="strataTrigger"">item3</a></li>
</ul>


when one clicks on an anchor, i need to get the index of that anchor
's LI inside it UL.

i managed to do it like this, and i would like to know if there is an
easier/smarter way to do it. Knowing jquery, there must be!!

                $('.strataTrigger').bind('click',function(){
                        var $thisMenu = $(this).parents('.mainmenu');
                        $thisMenu.css({backgroundColor: 'red'});
                        var $thisMenuItems = $('li', $thisMenu);
                        var $thisItem = $(this).parent().get(0);
                        var index = $thisMenuItems.index($thisItem);
                        console.log("index="+index);
                        return false;
                });


thanks for your feedback!


alexandre

Reply via email to