:first Selector
Selects the first matched DOM element.
.first()
As of jQuery 3.4, the :first
pseudo-class is deprecated. Remove it from your selectors and filter the results later using .first()
.
The :first
pseudo-class is equivalent to :eq( 0 )
. It could also be written as :lt( 1 )
. While this matches only a single element, :first-child can match more than one: One for each parent.
Finds the first table row.
JS
<table>
<tr>
<td>Row 1</td>
</tr>
<tr>
<td>Row 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
</table>
CSS
td {
color: blue;
font-weight: bold;
}
HTML
$("tr:first").css("font-style", "italic");
DEMO