How to get the position of an specific li in a ul

2019-03-02 07:26发布

I want to get number of one li that I hover on with jQuery. this is my code :

<ul>
   <li></li>
   <li></li>
   <li></li> /* I want hover on this element */
   <li></li>
   <li></li>
</ul>

I want when hover on certain element in top code get number of all lies.... for example in top code I want get 3 (This means that this third element)

1条回答
时光不老,我们不散
2楼-- · 2019-03-02 07:46

You can use this:

var number = $(this).index() + 1;

Demo here

The .index() starts at 0 so I added +1 because you wanted to start counting from 1.

查看更多
登录 后发表回答