jQuery select all except first or a specific one

Javascript Feb 07, 2020 Viewed 639 Comments 0

Use jquery's selector and related methods to select all elements but not include the first (or a specific one) element. There are several ways.

:not and :first selector

The jquery api about :not selector 和 :first selector.

$("tr:not(:first)").css( "font-style", "italic" );

Try it Yourself »

:eq selector

The jquery api about :eq selector

$("tr:not(:eq(0))").css( "color", "red" );

Try it Yourself »

not method

The jquery api about not function.

$("div").not(":eq(0)").css("border-color", "red");

Try it Yourself »

:gt selector

The jquery api about gt selector.

$("tr:gt(0)").css("backgroundColor", "yellow");

Try it Yourself »

slice method

The jquery api about slice method.

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

Try it Yourself »

Updated Feb 07, 2020