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

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

I have a list like this one:

  • ....
  • ....
  • ....
  • ....
  • 2条回答
    •  星月不相逢
      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.

    提交回复
    热议问题