Removing all li elements inside a ul except first and last elements

by Subramanian 2014-07-21 15:15:55

Removing all li elements inside a ul except first and last elements:
 
$('#id li:not(:first):not(:last)').remove();

If you want to remove only last li, then
 
$('#id li:not(:last)').remove();


Example :
 
<ul id='ulList'>
   <li>This</li>
   <li>is</li>
   <li>GvSubhu</li>
</ul>
 
<script>
$('#ulList li:not(:last)').remove();
</script>

OutPut: 
 
<ul id='ulList'>
   <li>GvSubhu</li>
</ul>
1061
like
0
dislike
0
mail
flag

You must LOGIN to add comments