Thank you, Alex! It did indeed point me in the right direction. I tested it
and there is one small bug. The code reading:
index($(this).parent(li)[0])
I discovered was missing quotes and should read:
index($(this).parent("li")[0])

Otherwise, it worked terrific! Thank you for the help!

The revised full code is:

$(document).ready( function() {
  $('#articlesIndex li a').click( function() {
        currIndex = $("#articlesIndex ul li").index($(this).parent("li")[0]);
        alert("You just clicked list item number: " + currIndex);
        return false; // prevents the hyperlink from firing
  });
});


Alex Cook wrote:
> 
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of Matt
> Subject: [jQuery] How to tell numerically which sibling element
> I'vetriggered?
> 
> 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?
> -----
> 
> You're close, you want to look at .index()[1] and use that. Here is some
> untested code that should point you in the right direction.
> 
> $(document).ready( function() {
>   $('#articlesIndex li a').click( function() {
>       currIndex = $("#articlesIndex ul
> li").index($(this).parent(li)[0]);
>       alert("You just clicked list item number: " + currIndex);
>       return false; // prevents the hyperlink from firing
>   });
> });
> 
> Basically we are grabbing all the LI elements within #articleIndex and
> then finding the index of the LI that contains the A element the user
> clicked on in the first place.
> 
> [1] - http://jquery.bassistance.de/api-browser/#indexElement
> 
> -ALEX
> 
> 

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


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

Reply via email to