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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With