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>a</li>
    <li>b</li>   
     <li>c</li>
     <li>d</li>
     <li>e</li>
    <li>f</li>
 </ul>

$('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 http://jsfiddle.net/sHefJ/

+3


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

.

+6


source


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



$(this).index();

      

+2


source







All Articles