Jquery how to remove the first x div?
i try to remove the first 4 divs if i click the button:
<div class="test"> <div class="1"></div> <div class="1"></div> <div class="1"></div> <div class="1"></div> <div class="1"></div> <div class="1"></div> </div> i; ve tried this but seems to remove them one by one:
if ($('.test').find('.1').size() >= 4) { $('.test').find('.1').remove(); } thanks
+4
2 answers
Use the selector :lt() .
$('.test').find('.1:lt(4)').remove(); Demo: http://jsfiddle.net/mattball/kR3wL/
NB "1" is not a valid class.
+11