How can I get the index of the clicked element in a list?
So if I have the following list:
- First
- Second
- Third
When I click Third, I would like to get the index 2, provided the index starts with 0.
With my code I only get 0s:
HTML:
<ul>
<li><a href="#" class="listElem">First</a></li>
<li><a href="#" class="listElem">Second</a></li>
<li><a href="#" class="listElem">Third</a></li>
</ul>
JS:
$(".listElem").click(function(param) {
console.log($(this).index());
});