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)')
精彩评论