How can I find the last “li” in a “ul” using jQuery?

后端 未结 5 2075
南方客
南方客 2021-01-04 18:15

I want to check the li that is the last li in ul. How can I check that using jQuery?

5条回答
  •  孤独总比滥情好
    2021-01-04 19:03

    Just use the following

    if($('#ulscroller li:last-child')[0] == liTocheck)
    {
       alert("This is the last li");
    }
    

    Or

    if($('#ulscroller li').last()[0] == liTocheck)
    {
       alert("This is the last li");
    }
    

    Here liTocheck is the li that needs to be compared

提交回复
热议问题