Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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').removeLast().each(fct());

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

Thanks.

like image 976
Nicolas Guillaume Avatar asked Apr 29 '10 08:04

Nicolas Guillaume


2 Answers

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

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

or

$('#menus>ul>li>a').not(":last")
like image 196
RoToRa Avatar answered Nov 05 '22 16:11

RoToRa


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

$('#menus > ul > li > a:not(:last)')
like image 21
Jimmy Avatar answered Nov 05 '22 16:11

Jimmy