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

jQuery :last-of-type Selector

jQuery Selectors

:last-of-type selector selects all elements that are the last child of their parent element of a specific type.

This is similar to the :nth-last-of-type(1)is the same.

Using:first-of-typeSelectors can choose all elements that are the first child of their parent element of a specific type.

Syntax:

$(":last-of-$("type")

Example

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

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

Select all <div> elements containing the last <p> element:

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

jQuery Selectors