Reputation: 27048
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
Upvotes: 5
Views: 7437
Reputation: 227270
Use the :lt
selector
$('div.1:lt(4)', 'div.test').remove()
Example: http://jsfiddle.net/JD6CY/
Upvotes: 1
Reputation: 359836
Use the :lt()
selector.
$('.test').find('.1:lt(4)').remove();
Demo: http://jsfiddle.net/mattball/kR3wL/
N.B. "1" is not a valid class.
Upvotes: 12