thanks richard, i'll learn from it!

On 14 déc, 15:51, "Richard D. Worth" <[EMAIL PROTECTED]> wrote:
> This is a little slimmer, but not all that different from what you're doing:
>
>   $('.strataTrigger').click(function() {
>     var li = $(this).parent();
>     var index = li.parent().css({backgroundColor:
> 'red'}).children('li').index(li[0]);
>     console.log("index=" + index);
>     return false;
>   });
>
> - Richard
>
> On Dec 14, 2007 8:07 AM, pixeline <[EMAIL PROTECTED]> wrote:
>
>
>
> > 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