From jQuery JavaScript Library
« Back to Traversing
eq( index )
Reduce the set of matched elements to a single element.
The position of the element in the set of matched elements starts at 0 and goes to length - 1.
Arguments:| index | Integer | |
|---|
| The index of the element in the jQuery object. |
Examples:| Name | Type |
Turn the div with index 2 red by adding an appropriate class.
$("div").eq(2).addClass("red");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="../jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("div").eq(2).addClass("red");
});
</script>
<style>
div { width:60px; height:60px; margin:10px; float:left;
border:2px solid blue; }
.red { background:red; }
</style>
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html>