开发者

How to remove the last element of a jQuery selection?

开发者 https://www.devze.com 2022-12-28 09:01 出处:网络
I use a jquery selector : $(\'#menus>ul>li>a\') I\'d like to to iterate the selector result without the last one:

I use a jquery selector :

$('#menus>ul>li>a')

I'd like to to iterate the selector result without the last one:

$('#menus>ul>li>a').removeL开发者_开发问答ast().each(fct());

Ofcourse the function "removeLast()" doesn't exist, is there an equivalent ?

Thanks.


You can use the :not selector or the .not() method:

$('#menus>ul>li>a:not(:last)')

or

$('#menus>ul>li>a').not(":last")


Use a combination of the :not and :last selectors:

$('#menus > ul > li > a:not(:last)')
0

精彩评论

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