:lt() Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:lt

Description

The :lt() selector selects elements with an index number less than a specified number.

The index numbers start at 0.

Syntax

Parameter Description
index Required. Elements with an index lesser than the specified number is selected.

The following code shows how to select the 4 first <tr> elements:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("tr:lt(4)").css("background-color", "yellow");
});/*from   w ww . j a va  2  s. c  o 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>A</td>
    <td>B</td>
    <td>G</td>
  </tr>
  <tr>
    <td>C</td>
    <td>C</td>
    <td>D</td>
  </tr>
  <tr>
    <td>E</td>
    <td>F</td>
    <td>G</td>
  </tr>
  <tr>
    <td>E</td>
    <td>R</td>
    <td>A</td>
  </tr>
  <tr>
    <td>I</td>
    <td>H</td>
    <td>U</td>
  </tr>
  <tr>
    <td>K</td>
    <td>P</td>
    <td>G</td>
  </tr>
  <tr>
    <td>L</td>
    <td>Y</td>
    <td>C</td>
  </tr>
 <tr>
    <td>M</td>
    <td>G</td>
    <td>I</td>
  </tr>
  <tr>
    <td>N</td>
    <td>S</td>
    <td>U</td>
  </tr>
</table>

</body>
</html>

Related Tutorials