> > If you just want the loop index, it's passed to the .each() callback as the
> > first parameter:
>
> >     $('a').each( function( i ){
> >         // 'i' is the loop index
> >         $(this).click(function(){
> >             // You can use 'i' directly in this code
> >         });
> >     });
>

> Now, imagine you have the following html items
>
> <div id="myLinks">
>    <a href="#">link 1</a>
>    <a href="#">link 2</a>
>    <a href="#">link 3</a>
> </div>
>
> Basically, I want to do is have jQuery make each link call myFunction
> when clicked and pass its index so the the correct switch statement is
> fired...

I think Michael Geary already posted exactly what you want, after a
slight modification :)


     $('#myLinks a').each( function( i ){
         // 'i' is the loop index
         $(this).click(function(){
             // You can use 'i' directly in this code
             alert("You clicked on link #" + i);
        });
     });

Reply via email to