Trying to remove all li elements inside a ul except first and last elements in jQuery? Here is the code to do this.
Suppose, you have a ul li list and you need to remove all the li elements inside it except first and last li.
So, to remove from all ul-s on the page the li-s that are neither the first nor the last:
Sample HTML:
<ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> </ul>
$('ul li:not(:first):not(:last)').remove();
Or you can use with a specific id:
$('#YOURID li:not(:first):not(:last)').remove();
Over the years, people have experimented with various methods to maintain healthy and beautiful hair.…
Your brand more than developing an attractive and creative logo and infectious motto. It's the…
Introduction Are you someone who has suffered from a personal injury and want to file…
Operating from home has emerged as one of the most popular ways of doing jobs…
If the consequences of our society’s ever-growing debt are what worries you, then it is…
No matter how much competition is there, a well-planned franchise marketing strategy can scale up…
View Comments
Useful. Thanks.