Here is the HTML:
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
Here is the Jquery:
if ( $( ".line" ).length > 2 ) {
//remove all other div.lines but keep the first 2
}
How do you do this?
You can use Jquery’s gt selector. This select that indexes which are greater than 1.
See jsfiddle http://jsfiddle.net/X7a4Z/1/.