.eq()
** DEPRECATED **S2C Home « Filtering « .eq()
Filter elements.
Description
The .eq()
method is used to reduce the matched set to the element at the specified index.
This method was deprecated in jQuery 3.4.
Syntax
Signature | Description |
---|---|
.eq( index ) | Reduce the matched set to the element at the specified index. |
.eq( -index ) | Reduce the matched set to the element at the specified index, counting backwards from the last element in the set. |
Parameters
Parameter | Description | Type |
---|---|---|
index | An integer indicating the 0-based position of the element. | Number |
-index | An integer indicating the position of the element, counting backwards from the last element in the set. | Number |
Return
A jQuery
object containing the filtered element.
.eq( index )
ExampleTop
Reduce the matched set to the element at the specified index.
In the example we select the third 'td' element and change the background colour.
Table Row 1, Table Data 1 | Table Row 1, Table Data 2 |
Table Row 2, Table Data 1 | Table Row 2, Table Data 2 |
$(function(){
$('#btn6').on('click', function() {
$('.testtable td').eq(2)
.css('backgroundColor', 'orange');
});
});
.eq( -index )
ExampleTop
Reduce the matched set to the element at the specified index, counting backwards from the last element in the set.
In the example we select the second 'td' element from the end and change the background colour.
Table Row 1, Table Data 1 | Table Row 1, Table Data 2 |
Table Row 2, Table Data 1 | Table Row 2, Table Data 2 |
$(function(){
$('#btn7').on('click', function() {
$('.testtable2 td').eq(-2)
.css('backgroundColor', 'orange');
});
});
Related Tutorials
jQuery Intermediate Tutorials - Lesson 1 - Filtering Elements