Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery removeClass for all but the first item?

I'm doing the following right now which works great:

 $('#picker a').removeClass('selected');

where:

<div id="picker">
 <a href="" class="selected">Stuff</a>
 <a href="" class="selected">Stuff</a>
 <a href="" class="">Stuff</a>
 <a href="" class="selected">Stuff</a>
</div>

How can I update the jQuery to say, remove class selected from all BUT the first row. Ignore the first row in picker.

Thanks

like image 941
AnApprentice Avatar asked Jan 27 '11 23:01

AnApprentice


2 Answers

$('#picker > a').slice(1).removeClass('selected');

This uses a valid querySelectorAll selector, along with the slice()(docs) method which will be very fast.

like image 70
user113716 Avatar answered Oct 06 '22 21:10

user113716


Negate :first, like this:

$('#picker a:not(:first)').removeClass('selected');
like image 21
BoltClock Avatar answered Oct 06 '22 22:10

BoltClock