.first()
** DEPRECATED **S2C Home « Filtering « .first()
Filter first element.
Description
The .first()
method is used to reduce the matched set to the first element.
This method was deprecated in jQuery 3.4.
Syntax
Signature | Description |
---|---|
.first() | Reduce the matched set to the first element. |
Parameters
None
Return
A jQuery
object containing the first element of the matched set.
.first()
ExampleTop
Reduce the matched set to the first element.
In the example below we select all 'td' elements within the table with the class of 'testtable' and then reduce the matched set to the first element.
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(){
$('#btn1').on('click', function() {
$('.testtable td').first()
.css('backgroundColor', 'orange');
});
});
Related Tutorials
jQuery Intermediate Tutorials - Lesson 1 - Filtering Elements