:gt() Selector

Select all elements at an index greater than index within the matched set.

.gt(index)

index NumberZero-based index.

.gt(indexFromEnd)

indexFromEnd IntegerZero-based index, counting backwards from the last element.

As of jQuery 3.4, the :gt pseudo-class is deprecated. Remove it from your selectors and filter the results later using .slice(). For example, :gt(3) can be replaced with a call to .slice( 4 ) (the provided index needs to be increased by one).

index-related selectors

The index-related selector expressions (including this "greater than" selector) filter the set of elements that have matched the expressions that precede them. They narrow the set down based on the order of the elements within this matched set. For example, if elements are first selected with a class selector (.myclass) and four elements are returned, these elements are given indices 0 through 3 for the purposes of these selectors.

Note that since JavaScript arrays use 0-based indexing, these selectors reflect that fact. This is why $( ".myclass:gt(1)" ) selects elements after the second element in the document with the class myclass, rather than after the first. In contrast, :nth-child(n) uses 1-based indexing to conform to the CSS specification.

Prior to jQuery 1.8, the :gt(index) selector did not accept a negative value for index

Give TD #5 and higher a yellow background and TD #8 a red text color.

JS
<table border="1">
  <tr>
    <td>TD #0</td>
    <td>TD #1</td>
    <td>TD #2</td>
  </tr>
  <tr>
    <td>TD #3</td>
    <td>TD #4</td>
    <td>TD #5</td>
  </tr>
  <tr>
    <td>TD #6</td>
    <td>TD #7</td>
    <td>TD #8</td>
  </tr>
</table>
HTML
$("td:gt(4)").css("backgroundColor", "yellow");
$("td:gt(-2)").css("color", "red");
DEMO

Looking for a Web Developer?

👋

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)