开发者

How to remove the last element of a jQuery selection?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜