find number of nodes between two elements with jquery?

后端 未结 2 552
名媛妹妹
名媛妹妹 2020-12-12 03:13

I\'m having a little trouble figuring out a fast way to accomplish a (seemingly) simple task. Say I have the following html:

  • One
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 03:48

    Try the closest() function

    http://docs.jquery.com/Traversing/closest#expr

    This will give you the total number of ul parents:

    var numofuls = $(this).parents('ul').length;

提交回复
热议问题