jquery selector before-last

后端 未结 2 760
忘了有多久
忘了有多久 2021-01-03 20:22

I have a dynamic list and need to select the before last item.

  • &l
相关标签:
2条回答
  • 2021-01-03 20:40

    Probably a neater way but how about:

    var lastLiId = $(".album li:last").prev("li").attr("id");
    
    0 讨论(0)
  • 2021-01-03 20:51

    You can use .eq() with a negative value (-1 is last) to get n from the end, like this:

    $(".album li").eq(-2).attr("id"); // gets "li-9"
    

    You can test it here.

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