jQuery Greater than selector

Description and Syntax

$(':gt(index)')

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

  • $('li:gt(2)') selects all <li> elements following the third one
  • $('.myclass:gt(1)') selects all elements with the class myclass following the second one

Examples

The following code selects the second table row.


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--   w w w .  j a  va  2s.co m-->
                
            $("tr:gt(1)").css("background-color", "red");
                
        });
    </script>

  </head>
  <body>
    <body>
    <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>

    </body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Tutorial »




Basics
Selector
DOM
Event
Effect
Utilities