Less than (:lt(n))
In this chapter you will learn:
Description and Syntax
$(':lt(index)')
selects all elements at an index less than n
within the matched set.
$('li:lt(2)')
selects all<li>
elements preceding the third one$('.myclass:lt(1)')
selects all elements with the classmyclass
preceding the second one
Examples
The following code selects the first two table cells.
<html><!-- j a v a 2 s.c om-->
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("td:lt(2)").css("color", "red");
});
</script>
</head>
<body>
<body>
<table>
<tr><td>First</td></tr>
<tr><td>Middle</td></tr>
<tr><td>Last</td></tr>
</table>
</body>
</html>
Next chapter...
What you will learn in the next chapter:
- Description and Syntax for first selector
- Examples for first selector
- How to select the first span
- How to use first selector and id selector
- How to select the first row