ドキュメント

Selectors/lt

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

:lt(index)

Matches all elements with an index below the given one.
Arguments:
indexNumber
Zero-based index.
Examples:

Finds TDs less than the one with the 4th index (TD#4).

$("td:lt(4)").css("color", "red");

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $("td:lt(4)").css("color", "red");
  });
  </script>
  
</head>
<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>

NameType