Reputation: 48091
<div class="box"></div>
<div class="box"></div> <!-- Hide -->
<div class="box"></div> <!-- Hide -->
<div class="box"></div> <!-- Hide -->
I need to hide all this div but not the first div.
I could do something like this:
jQuery('.box').hide();
jQuery('.box').first().show();
Is there a way to remove the first .box
from the array before .hide()
em?
Upvotes: 15
Views: 18921
Reputation: 31033
try
jQuery('.box').not(':first').hide();
comparison:
@T.J.Crowder is right the code i have suggested does the extra parsing that can be avoided by .slice
as suggested by @zch
HERE is the profile of my code (0.8ms) and HERE is the profile of @zch's code (0.53ms) see the difference
Upvotes: 6
Reputation: 2381
jQuery('.box').not(':eq(0)').hide();
That said, I prefer Residual Envy's solution.
Upvotes: 1