Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all elements after certain element

Tags:

jquery

My code is:

<div id="wrap">   <div id="element1" class="ewrap"></div>   <div id="element2" class="ewrap"></div>   <div id="element3" class="ewrap"></div>   <div id="element4" class="ewrap"></div>   <div id="element5" class="ewrap"></div> </div> 

How would I dynamically remove all elements after element1?

like image 651
Damien Roche Avatar asked Jul 10 '11 13:07

Damien Roche


1 Answers

You could use the .nextAll() method:

$('#element1').nextAll('div').remove(); 
like image 110
Darin Dimitrov Avatar answered Sep 30 '22 09:09

Darin Dimitrov