Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove item from list

I want to remove all the li from my unordered list but I want to keep the li before the last li anybody an idea how it's done ?

I now have

$('.pagination ul li:not(:last)').remove();

but that removes everything but the last one so it isn't correct

like image 432
user1994529 Avatar asked Apr 11 '13 09:04

user1994529


1 Answers

Use :eq() with a negative index - this will count from the end of the collection instead of the beginning.

In your case, you'll want to use an index of -2 (-1 would be the last <li>), like so:

$('.pagination ul li:not(:eq(-2))').remove();

Here's a quick demonstration.

like image 163
Bojangles Avatar answered Oct 04 '22 05:10

Bojangles