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

后端 未结 5 2064
南方客
南方客 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:09

    Just use the :last-child selector :

    $('#ulscroller li:last-child')
    

    DEMO: http://jsfiddle.net/f5v6R/

    For example, if you want to know if it has the selected class you may do

    if ($('#ulscroller li:last-child').hasClass('selected')) {
       // do something
    }
    

提交回复
热议问题