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:
<ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> </ul>
Or you can use with a specific id: