I have a <ul>
element. How can remove all the <li>
elements inside it, except for the first and the last, using jQuery?
To remove from all ul-s on the page the li-s that are neither the first nor the last:
$('ul li:not(:first-child):not(:last-child)').remove();
Or using a specific id:
$('#yourul li:not(:first-child):not(:last-child)').remove();
If you have a jQuery object with your ul in it:
$(yourul).find('li:not(:first-child):not(:last-child)').remove();