I've tried both methods suggested here, and both work beautifully. I noticed
you took into account the counter starting at zero rather than 1; very
thoughtful! Thank you for the help!


AHeimlich wrote:
> 
> Try this:
> 
> $(document).ready( function() {
>   var $listItems = $("#articlesIndex li");
>   $listItems.find('a').click( function() {
>      var itemNum = $listItems.index($(this).parent()[0]) + 1;
>      alert("You just clicked list item number: " + itemNum);
>      return false; // prevents the hyperlink from firing
>   } );
> } );
> 
> 
> On 3/12/07, Matt <[EMAIL PROTECTED]> wrote:
>>
>> I have an unordered list like this:
>>
>> <div id="articlesIndex">
>> <ul>
>>     <li> "article01.php First Article </li>
>>     <li> "article02.php Second Article </li>
>>     <li> "article03.php Third Article </li>
>> </ul>
>> </div>
>>
>> I cannot figure out how (or whether) I can use jQuery to read "which LI
>> element has just been clicked" as a numeric index. Here is a simplified
>> example code:
>>
>> $(document).ready( function() {
>>   $('#articlesIndex li a').click( function() {
>>      alert("You just clicked list item number: ");
>>      return false; // prevents the hyperlink from firing
>>   } );
>> } );
>>
>> Now how do I pass the number so that the alert "You just clicked list
>> item
>> number: " is followed by the number just clicked on? 
> 
> -- 
> Aaron Heimlich
> Web Developer
> [EMAIL PROTECTED]
> http://aheimlich.freepgs.com
> 
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-tell-numerically-which-sibling-element-I%27ve-triggered--tf3391335.html#a9443495
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to