Jquery removeClass for all but the first element?

I am doing the following right now, which works fine:

 $('#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 jQuery to say remove the class selected from all BUTs of the first row. Ignore the first row in the picker.

thank

+5
source share
4 answers
$('#picker > a').slice(1).removeClass('selected');

In this case, a valid selector is used querySelectorAll, as well as a method slice() (docs) which will be very fast.

+5
source

Cancel :first, for example:

$('#picker a:not(:first)').removeClass('selected');
+3
source

, :

$('#picker a').not(':first-child').removeClass('selected');
+1

:)

$('#picker a:gt(0)').removeClass('selected');
+1

All Articles