jQuery :gt() Selector — Index Greater Than

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

What Is the :gt() Selector?

: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.

Remember
$("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)
NeedUse
Elements after index n$("el").slice(n + 1) · legacy $("el:gt(n)")
Elements before index n:lt(n) · .slice(0, n)
Exactly one index:eq(n)
Even / odd positions:even / :odd
CSS nth child (1-based):nth-child()

How to Use :gt()

Build a matched set first, then keep only items after a given index — or migrate to .slice().

  1. Select a set ($("td"), $("li"), …).
  2. Choose a zero-based cut-off index (strictly greater than).
  3. Legacy: append :gt(index) · Modern: call .slice(index + 1).
  4. For counting from the end (1.8+), use a negative index or .slice(-n).
  5. Style or act on the filtered set.
PieceRequired?Role
Preceding selectorYesBuilds the set that :gt / .slice filters
indexYesZero-based; keep items with index > this value
Negative indexNoSince 1.8 — count from the end
Return value—jQuery set of matching elements

Pseudocode

Pseudocode
set = $(precedingSelector)   // indices 0 … length-1

call set.filter(":gt(index)")
  // or set.slice(index + 1)

for each element at position i in set:
    if i > index:
        include it

return the filtered jQuery set

Cheat Sheet

Keep these facts handy while filtering by index.

TopicDetail
Syntax$("sel:gt(index)")
Since1.0 · negative index since 1.8
DeprecatedjQuery 3.4 — prefer .slice()
Migration:gt(n) → .slice(n + 1)
Indexing0-based (like JS arrays)
Includes index?No — strictly greater than
vs :eq:gt = range · :eq = one item
vs :nth-childSet position vs parent child (1-based CSS)

Live Preview

Highlight table cells with :gt() or the modern .slice() equivalent.

TD #0TD #1TD #2
TD #3TD #4TD #5
TD #6TD #7TD #8

Yellow cells match the filter. :gt(4) and .slice(5) select the same cells.

Result
Ready — click Run to filter cells.

jQuery Examples

Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.

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.
  4. css. Applies styles to those filtered cells.

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.
  4. Future-proof. Avoids the deprecated pseudo-class.

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.
  4. slice(1). Same result without :gt.

Example 4 — :gt() vs :eq()

Range after an index versus a single element at that index.

jQuery
$("#output").text(
  ":gt(2) → " + $("td:gt(2)").length + " cells\n" +
  ":eq(2) → " + $("td:eq(2)").length + " cell"
);
$("td:eq(2)").css("outline", "3px solid #2563eb");
$("td:gt(2)").css("backgroundColor", "#fef9c3");
Try It Yourself

How It Works

  1. eq(2). Picks exactly the third cell.
  2. gt(2). Picks everything after that cell.
  3. Count. One vs many — different jobs.
  4. Visual. Outline on eq; yellow on gt range.

Example 5 — Negative Index :gt(-2)

Count from the end (since 1.8) to style the last cell.

jQuery
$("td:gt(-2)").css({ fontWeight: "bold", color: "red" });
$("#log").text("Matched: " + $("td:gt(-2)").map(function () {
  return $(this).text();
}).get().join(", "));
// Modern: $("td").slice(-1)
Try It Yourself

How It Works

  1. -2. Means “greater than second-from-last”.
  2. Match. Only the final index (8) qualifies.
  3. map. Collects matched text for the log.
  4. slice(-1). Modern way to take the last item.

Edge Cases & Pitfalls

CaseWhat happensFix
Thinking :gt(1) includes index 1Index 1 is excludedRemember: strictly greater than
Confusing with :nth-childWrong element — different indexing0-based set filter vs 1-based CSS child
New code on jQuery 3.4+Deprecated warning / future riskUse .slice(n + 1)
Negative index before 1.8Not supportedRequire jQuery 1.8+ or use .slice(-n)
Bare $(":gt(0)")No useful preceding setAlways prefix: $("li:gt(0)")

Browser Support

:gt() has been part of jQuery since 1.0 (negative indices since 1.8). It still works, but is deprecated since jQuery 3.4 — prefer .slice() for new code.

✓ Deprecated · jQuery 1.0+

jQuery :gt()

Works across jQuery 1.x–3.x where loaded, but avoid in new projects. Migrate to $("sel").slice(n + 1) for better performance and future compatibility.

Legacy Status
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
:gt() Deprecated 3.4+

Bottom line: Fine for reading older tutorials. For production on jQuery 3.4+, use .slice() instead of :gt().

Performance Notes

ApproachCostBest for
$("css").slice(n)BestModern browsers + jQuery 3.4+
$("el:gt(n)")SlowerLegacy code only — no querySelectorAll
Huge lists filtered oftenCan add upCache the set; prefer slice once

Because :gt() is a jQuery extension, the engine cannot hand the whole query to the browser. Select with CSS, then .slice(), for the fastest path.

Key Takeaways

  • Role: keep items after a 0-based index — since jQuery 1.0.
  • Migrate: :gt(n) → .slice(n + 1) (deprecated 3.4).
  • Strict: index n itself is not included.
  • Negative: :gt(-2) since 1.8 · or .slice(-1) for the last item.

One line: :gt(n) keeps elements after index n — prefer .slice(n + 1) in modern jQuery.

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

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

:even tutorial →

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