var log = $('#log'); var log2 = $('#log2'); $('li').click(function(){ log.text('index of collection: ' + $(this).index()); log2.text('index of matched collection: ' + $(this).index('li.other')); });
<ul id="foo"> <li class="other">Beef Jerky</li> <li>Smoked Salmon</li> <li class="other">Rocky Mountain Oysters</li> <li class="other">Beef Jerky</li> <li>Smoked Salmon</li> <li class="other">Rocky Mountain Oysters</li> </ul> <h1 id="log">index of collection: waiting ...</h1> <h1 id="log2">index of matched collection: waiting ...</h1>