开发者

how to select ul li in jQuery

开发者 https://www.devze.com 2023-02-08 01:52 出处:网络
i have a ul li in jQuery and i want to select last li from the ul i make like <ul> <!-- many li here --->

i have a ul li in jQuery and i want to select last li from the ul i make like

<ul>
   <!-- many li here --->
   <li><a id="nqp2" class="apager" href="/2">
        next</a></li>
</ul>

how to select last div here without using :last in jQuery

the following thing can be used :>

  1. the id starting from char "n" like they always have id starting from "n" and all other not have these char starting from.

  2. the last li i want to select always have wor开发者_高级运维d next inside them.

are their any way to select li using any way of these two selection pattern


Using your first method:

$('li:has(a[id^="n"])')

Using your second method:

$('li:contains("next")')


With jQuery you can use classes and ids to select elements, same as CSS. In this case your last li has a class so:

$function (){
    $(".apager")... (rest of your jQuery)

It's best to always add a class or id if you'll be selecting it with jQuery/CSS :)


Jquery selector: $('ul li:last-child')

0

精彩评论

暂无评论...
验证码 换一张
取 消