<ul>
<li>one</li>
<li>element</li>
<li>text</li>
<li>val</li>
</ul>
how can i get the position in the ul
of the clicked li
?
<ul>
<li>one</li>
<li>element</li>
<li>text</li>
<li>val</li>
</ul>
how can i get the position in the ul
of the clicked li
?
I think this will do it for you:
$("li").click(function () {
alert($(this).index());
});
Note that the index() function returns the index of the item in the jquery collection. If you have multiple lists on the page, make sure your selector only selects the list items that you want.