jQuery :gt() Selector — Index Greater Than

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

:gt(index) (since jQuery 1.0) selects elements whose zero-based index in the matched set is greater than index. Negative indices (from the end) are supported since 1.8.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("td:gt(4)");              // indices 5, 6, 7, 8 …
$("li:gt(0)");              // skip the first item
$("td:gt(-2)");             // last cell (since 1.8)

// Preferred today (jQuery 3.4+):
$("td").slice(5);           // same as :gt(4)
CallWhat it does
Preceding selectorBuilds the set that :gt / .slice filters
indexZero-based; keep items with index > this value
Negative indexSince 1.8 — count from the end
Return valuejQuery set of matching elements

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select a set ($("td"), $("li"), …).
Step 2Choose a zero-based cut-off index (strictly greater than).
Step 3Legacy: append :gt(index) · Modern: call .slice(index + 1).

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

Example 1 — Official td:gt(4) / td:gt(-2)

From the jQuery docs: yellow on TD #5+, red text on TD #8.

jQuery
$("td:gt(4)").css("backgroundColor", "yellow");
$("td:gt(-2)").css("color", "red");
Try It Yourself

How It Works

  1. Set. All td cells get indices 0–8.
  2. gt(4). Keeps only indices strictly after 4.
  3. gt(-2). Counts from the end; last cell matches.

Example 2 — Modern .slice(5)

Same yellow cells as :gt(4) — the recommended jQuery 3.4+ replacement.

jQuery
$("td").slice(5).css("backgroundColor", "yellow");
// Same matches as $("td:gt(4)")
Try It Yourself

How It Works

  1. Rule. :gt(n) ↔ .slice(n + 1).
  2. slice(5). Starts at index 5 through the end.
  3. CSS path. Pure CSS select + slice can use querySelectorAll.

Example 3 — Skip the First Item

Dim every list item after the first with li:gt(0).

jQuery
$("ul.features li:gt(0)").css("opacity", "0.6");
// Modern: $("ul.features li").slice(1)
Try It Yourself

How It Works

  1. Set. List items are indexed 0, 1, 2, 3.
  2. gt(0). Drops index 0; keeps the rest.
  3. Style. Only the trailing items are dimmed.

Frequently Asked Questions

:gt(index) selects every element whose zero-based index in the matched set is greater than index. $("td:gt(4)") matches TD #5 and higher (indices 5–8) in the official demo. Available since jQuery 1.0.
It selects elements after the second one — indices 2, 3, 4, and so on. Index 1 itself is not included because :gt means strictly greater than.
Since jQuery 1.8, :gt(-index) counts backwards from the last element. In the official demo, $("td:gt(-2)") styles TD #8 — the last cell among nine TDs (indices 0–8).
Yes — deprecated in jQuery 3.4. Official docs recommend removing :gt() from selectors and using .slice() instead: $("td").slice(5) replaces $("td:gt(4)") — add 1 to the gt index for slice.
:gt() filters the jQuery matched set by 0-based position after the preceding selector. :nth-child(n) is CSS — it picks elements that are the nth child of their parent (1-based). They use different indexing models.
:gt() always follows a selector that builds the matched set — for example $("li:gt(0)"), not $(":gt(0)"). Index selectors narrow the set produced by what comes before them.

Next: :even Selector — Even-Indexed Elements

Select even-indexed elements in a matched set — another index filter.

:even Selector — Even-Indexed Elements tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful