jQuery - get the index of a element with a certain class

前端 未结 2 1531
灰色年华
灰色年华 2020-12-16 09:30

I have a list like this one:

  • ....
  • ....
  • ....
  • ....
  • 相关标签:
    2条回答
    • 2020-12-16 10:14

      With the .index() :

      $('li.active').index()
      

      Working example here:

      http://jsfiddle.net/EcZZL/

      Edit - added link to the api for .index() per Nick's advice

      0 讨论(0)
    • 2020-12-16 10:17

      Like this:

      var index = $("ul li.active").index();
      

      .index() without parameters gives the index of the element with respect to it's siblings, which is what you want in this case.

      0 讨论(0)
    提交回复
    热议问题