English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
:first-of-type selector selects all elements that are the first child of the parent element of a specific type.
This is similar to the :nth-of-type(1)is the same.
Using:last-of-typeThe selector can select all elements that are the last child of the parent element of a specific type.
$":first-of-type")
Select each <p> element that is the first child of its parent element:
$("document").ready(function(){ $("p:first-of-type").css("background", "coral"); });Test and See‹/›
Select the first <p> element within all <div> elements:
$("document").ready(function(){ $("div p:first-of-type").css("background", "coral"); });Test and See‹/›