i an trying to remove the first 4 divs if i click a 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 it seems to remove them one by one:
if ($('.test').find('.1').size() >= 4) {
$('.test').find('.1').remove();
}
thanks
Use the :lt()
selector.
$('.test').find('.1:lt(4)').remove();
Demo: http://jsfiddle.net/mattball/kR3wL/
N.B. "1" is not a valid class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With