English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery :last-child selector

jQuery Selectors

:last-child selector to select the last child element of its parent element.

Using:first-childSelector to select the first child element of its parent element.

Syntax:

$(":last-child

Example

Select each <p> element that is the last child of its parent:

$(document).ready(function(){
  $("p:last-child").css("background", "coral");
});
Test and See‹/›

Select all last <p> elements within all <div> elements:

$(document).ready(function(){
  $("div p:last-child").css("background", "coral");
});
Test and See‹/›

jQuery Selectors