Get order of child selected jquery

I want to make a different background color for child cells depending on their orders, how can I get the order of the children using jquery.


$('ul li').bind('mouseover', function(e){

    //how can I get the order of the childre
    //when hover on c it shoul returns 3
    alert("child order ");


here's an example


source to share

2 answers

For this subset of HTML, using ...

$(this).index() + 1


jsFiddle .

... would be enough.

I added 1

because your numbering system in your example doesn't match 0




Below is the index. So c will be 2, not 3!





All Articles