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