jQuery select all except first

usertest picture usertest · Feb 13, 2010 · Viewed 165.8k times · Source

In jQuery how do I use a selector to access all but the first of an element? So in the following code only the second and third element would be accessed. I know I can access them manually but there could be any number of elements so thats not possible. Thanks.

<div class='test'></div>
<div class='test'></div>
<div class='test'></div>

Answer

karim79 picture karim79 · Feb 13, 2010
$("div.test:not(:first)").hide();

or:

$("div.test:not(:eq(0))").hide();

or:

$("div.test").not(":eq(0)").hide();

or:

$("div.test:gt(0)").hide();

or: (as per @Jordan Lev's comment):

$("div.test").slice(1).hide();

and so on.

See: