jQuery Selector :gt()

Introduction

The :gt() selector selects elements with an index number higher than a specified number.

The index numbers start at 0.

$(":gt(index)")
Parameter
Optional
Description
index

Required.

Specifies which element to select.
Elements with an index higher than the specified number is selected.

Select all <tr> elements after the 4 first:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("tr:gt(3)").css("background-color", "yellow");
});/*from w w  w  . jav a 2  s. co  m*/
</script>
</head>
<body>

<h1>Welcome to My Web Page</h1>

<table border="1">
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>CSS</td>
    <td>Java</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>A</td>
    <td>V</td>
    <td>Sweden</td>
  </tr>
  <tr>
    <td>Javascript</td>
    <td>Python</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>C++</td>
    <td>Q</td>
    <td>XYZ</td>
  </tr>
  <tr>
    <td>Ruby</td>
    <td>W</td>
    <td>UK</td>
  </tr>
  <tr>
    <td>C</td>
    <td>HTML</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>HTML5</td>
    <td>Yes</td>
    <td>Canada</td>
  </tr>
  <tr>
    <td>M</td>
    <td>Name</td>
    <td>Italy</td>
  </tr>
  <tr>
    <td></td>
    <td>Var</td>
    <td>UK</td>
  </tr>
</table>

</body>
</html>



PreviousNext

Related