HTML:
<ul>
<li>Help</li>
<li>me</li>
<li>Stack</li>
<li>Overflow!</li>
</ul>
<br>
<ul>
<li>Can</li>
<li>I</li>
<li>connect</li>
<li>these?</li>
</ul>
Javascript/JQuery:
$("li").live('click', function(){
alert($(this).index());
});
I put together a simple jsfilled page to help describe my problem: http://jsfiddle.net/T4tz4/
Currently clicking on an LI alerts the index relative to the current UL group. I’d like to know if it was possible to get a ‘global index’ so that clicking on “Can” returns the index value of 4.
Thank you,
John
Just put the
'li'selector insideindex()Live demo: http://jsfiddle.net/T4tz4/3/
http://api.jquery.com/index/