How manieth element is this?

javascript, jquery

Solution

You can use jQuery's `.index` for this.

​$("li").click(function() {
    var nth = $("ul li").index($(this));
    alert(nth);
});​

Live example

Problem

How do I know the how manieth an element is? (using Javascript or jQuery) Suppose I have one UL with multiple LI within, how do I know wheter the LI clicked is the 4th or the 6th? ``` $('li').click(function(){ nth = $(this).nth(); alert(nth); }); ```

Original source

Related problems