jQuery :gt() Selector

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
jQuery extension · deprecated 3.4

What You’ll Learn

The :gt(index) selector matches every element whose zero-based index in the matched set is greater than index. Negative indices since 1.8. jQuery extension since 1.0; deprecated in 3.4 — prefer .slice().

01

Syntax

td:gt(4)

02

> index

Strictly after

03

Official

yellow + red

04

Negative

Since 1.8

05

.slice()

index + 1

06

0-based

Like :eq()

Introduction

Index filters let you target a subset of an already matched collection — skip the first few table cells, hide trailing list items, or style everything after a cutoff. The jQuery :gt(index) pseudo-class selects elements after a given position in the matched set.

jQuery has supported :gt() since version 1.0; negative indices since 1.8. Official documentation states that index-related selectors filter the set matched by what precedes them and use 0-based indexing like JavaScript arrays — unlike CSS :nth-child(n), which is 1-based.

Understanding the :gt() Selector

Think of :gt(n) as “everything after index n in this matched set”:

  • $("td:gt(4)") → TD #5, #6, #7, #8 — indices 5 through 8 (official demo yellow cells).
  • $("li:gt(0)") → all list items except the first (index 0).
  • :gt(1) starts at index 2 — after the second element, not including it.
  • Negative :gt(-2) since 1.8 — official demo colors TD #8 red.
💡
Beginner Tip

:gt(3) maps to .slice(4) when migrating — add 1 to the gt index for .slice(). Need exactly one element at an index? Use :eq(n) or .eq(n) instead.

📝 Syntax

Official jQuery API form (since 1.0; negative since 1.8; deprecated 3.4):

jQuery
jQuery( ":gt(index)" )

// typical usage — prefix with element:
$( "td:gt(4)" )
$( "ul.nav li:gt(0)" )
$( "tr:gt(2)" )

// negative index (since 1.8):
$( "td:gt(-2)" )

// modern replacement (jQuery 3.4+ guidance):
$( "td" ).slice( 5 )   // replaces td:gt(4)

Parameters

  • index — zero-based cutoff; elements with index greater than this value match.
  • Negative index (since 1.8) — counts backwards from the last element in the matched set.

Return value

  • A jQuery object containing every matching element after the cutoff index.
  • Empty collection when no elements exceed the index.

Official jQuery API example

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

⚡ Quick Reference

Goal:gt().slice()
After TD #4 (from #5 up)td:gt(4)$("td").slice(5)
Skip first list itemli:gt(0)$("li").slice(1)
One exact indexUse :eq(n).eq(n)
Before an index:lt(n).slice(0, n)
Native CSSNot supportedjQuery method only

📋 :gt() vs :eq(), :lt(), and :nth-child()

Range filter vs single pick vs CSS sibling index.

:gt(n)
td:gt(4)

Index > n

:eq(n)
td:eq(4)

Exactly index n

:lt(n)
td:lt(4)

Index < n

:nth-child
li:nth-child(3)

1-based CSS

Examples Gallery

Example 1 follows the official jQuery td:gt(4) and td:gt(-2) demo. Examples 2–5 cover .slice() migration, skipping the first item, contrast with :eq(), and negative indices.

📚 Official jQuery Demo

Yellow background on TD #5+; red text on TD #8 via :gt(-2).

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

Official jQuery demo — cells #5–#8 yellow; cell #8 also red text.

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

How It Works

Nine cells indexed 0–8. :gt(4) keeps indices 5–8. :gt(-2) from the end matches the last cell (#8) in the official markup.

Example 2 — Modern Code: .slice() Instead of :gt()

jQuery 3.4+ guidance — :gt(4) becomes .slice(5).

jQuery
// legacy (deprecated selector):
// $( "td:gt(4)" ).css( "backgroundColor", "yellow" );

// recommended:
$( "td" ).slice( 5 ).css( "backgroundColor", "yellow" );
Try It Yourself

How It Works

Official docs: add 1 to the gt index when converting to slice — gt(4)slice(5).

📈 Practical Patterns

Skip leading items, single vs range, negative cutoff.

Example 3 — Skip First Item: li:gt(0)

Hide or style every list item after the first — common for “read more” lists.

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

How It Works

Index 0 is the first item; :gt(0) selects indices 1, 2, 3, … — equivalent to .slice(1).

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

Range after an index vs exactly one element at an index.

jQuery
console.log( ":gt(2) →", $( "td:gt(2)" ).length );  // TD #3–#8
console.log( ":eq(2) →", $( "td:eq(2)" ).length );  // TD #2 only
Try It Yourself

How It Works

:gt returns many elements; :eq returns one. Both use 0-based indexing in the matched set.

Example 5 — Negative Index: :gt(-2)

Since jQuery 1.8 — select elements after a cutoff counted from the end.

jQuery
$( "td:gt(-2)" ).css( "fontWeight", "bold" );
console.log( "Matched:", $( "td:gt(-2)" ).map(function() {
  return $( this ).text();
}).get().join( ", " ) );
Try It Yourself

How It Works

Negative gt counts from the last element in the matched set — prior to jQuery 1.8, negative values were not accepted.

🚀 Common Use Cases

  • Table styling — highlight td:gt(4) trailing columns per official demo.
  • Skip first itemli:gt(0) for secondary list styling.
  • Pagination UI — hide rows with tr:gt(9) before “show more” expands.
  • Legacy maintenance — read older code using index pseudo-classes.
  • Migration — replace with .slice(index + 1) in modern projects.
  • Pair with :lt() — combine range filters for middle segments (legacy pattern).

🧠 How jQuery Evaluates :gt()

1

Build matched set

Evaluate the selector before :gt(n) — e.g. all td elements in document order.

Query
2

Assign indices

Number elements 0, 1, 2, … in the matched set — official docs use 0-based indexing.

Index
3

Filter > n

Keep elements whose index is strictly greater than the argument.

Filter
4

Return collection

Chain .css(), .hide(), or other jQuery methods.

📝 Notes

  • Available since jQuery 1.0 — negative indices since 1.8 — deprecated in 3.4.
  • Replace :gt(n) with .slice(n + 1) — official migration guidance.
  • Strictly greater than — :gt(4) excludes index 4 itself.
  • 0-based indexing — unlike CSS :nth-child() (1-based).
  • jQuery extension — not valid in native querySelectorAll.
  • Index applies to the matched set from the preceding selector, not the whole document.

Browser Support

The :gt() pseudo-class is a jQuery extension — not standard CSS — and works in jQuery 1.0+ (negative indices 1.8+). It is deprecated in 3.4+; use .slice() instead. The method works in all browsers that support jQuery.

jQuery 1.0+ · deprecated 3.4

jQuery :gt() Selector

Use $("td").slice(5) in new code — not td:gt(4) in selector strings.

100% jQuery only
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

Bottom line: Migrate to .slice(index + 1) — select with CSS, then filter in jQuery.

Conclusion

The :gt(index) selector matches every element whose index in the matched set is greater than index — the official demo yellows TD #5 and up and reddens TD #8 via :gt(-2).

Remember 0-based indexing, the .slice(index + 1) migration path, and the difference from :eq() when you need one element vs a range.

💡 Best Practices

✅ Do

  • Use $("td").slice(5) in new jQuery code
  • Prefix with an element — li:gt(0) not bare :gt(0)
  • Add 1 when converting gt index to slice
  • Use :eq(n) when you need exactly one index
  • Scope with a parent selector when possible

❌ Don’t

  • Use :gt() in new selector strings (deprecated 3.4)
  • Confuse :gt(n) with :eq(n) — range vs single
  • Assume 1-based indexing — gt is 0-based
  • Expect :gt to work in querySelectorAll
  • Forget :gt(4) excludes index 4 itself

Key Takeaways

Knowledge Unlocked

Five things to remember about :gt()

Elements after index n in the matched set.

5
Core concepts
+1 02

.slice()

Migration

Tip
0 03

0-based

Like arrays

Rule
demo 04

Official

td yellow

Demo
05

Negative

Since 1.8

API

❓ 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, 6, 7, 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. The element at index 1 is the second item (0-based).
Since jQuery 1.8, :gt(-index) counts backwards from the last element. In the official demo, $("td:gt(-2)") turns TD #8 red — the last cell among nine TD elements (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 — e.g. $("li:gt(0)") not $(":gt(0)"). Index selectors narrow the set produced by what comes before them.
Did you know?

:gt(1) selects elements after the second item in the matched set (indices 2, 3, …), not the second item itself. That is why official docs say $(".myclass:gt(1)") skips the first two elements (indices 0 and 1) and starts at index 2.

Continue to :even Selector

After range index filters, learn how :even matches zero-indexed even positions for zebra striping.

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

6 people found this page helpful