jquery lt selector


  Translation results:

lt

abbr. Lithuania Lithuania

jquery lt selectorsyntax

Function::lt selector selects elements with a value less than the specified index. The index value starts from 0. Often used in conjunction with other elements/selectors to select elements before a specific number in a specified group (as in the example above).

Syntax: $(":lt(index)")

Parameters: index Required. Specifies the elements to be selected. Elements whose index value is less than the specified number will be selected.

Note: Please use the :gt selector to select elements whose index value is greater than the specified number.

jquery lt selectorexample

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript"> 
 
$(document).ready(function(){
    $("tr:lt(2)").css("background-color","#B2E0FF");
});
</script>	
</head>
<body>
<html>
<body>
<h1>Welcome to My Web Page</h1>
<table>
<tr>
<th>Id</th>
<th>LastName</th>

<th>FirstName</th>
<th>Address</th>
<th>City</th>
</tr>
<tr>
<td>1</td>
<td>Adams</td>
<td>John</td>
<td>Oxford Street</td>

<td>London</td>
</tr>
<tr>
<td>2</td>
<td>Bush</td>
<td>George</td>
<td>Fifth Avenue</td>
<td>New York </td>
</tr>
<tr>
<td>3</td>
<td>Carter</td>
<td>Thomas</td>
<td>Changan Street</td>
<td>Beijing</td>
</tr>
<tr>
<td>4</td>
<td>Obama</td>
<td>Barack</td>
<td>Pennsylvania Avenue</td>
<td>Washington</td>
</tr>
</table>
</body>
</html>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance

Home

Videos

Q&A