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

jQuery :nth-last-of-type() Selector

jQuery Selectors

:nth-last-of-The type() selector selects all elements of the given type based on their position among their sibling elements (starting from the end).

Using:nth-last-child()Selector, selects all elements of the specified type that are the nth child of their parent element, counting from the last child.

Syntax:

$(":nth-last-of-type(number|An+B|odd|even)

Example

Starting from the end, select the nth child element of its parent element:4Each <span> element inside each <span> element:

  -last-of-type(4).css("background", "lime");
});
Test and see‹/›

Odd and even keywords are used to match child elements with odd or even indices:

  -last-of-type(odd)
  -last-of-type(even)
});
Test and see‹/›

Parameter Value

ParameterDescription
numberThe index of each child element to be matched (from1End)
oddSelect every odd child element
evenSelect every even child element
An+BSpecify the child element to be selected
Example: p:nth-last-of-type(3n + 2Starting from the second paragraph, select every third paragraph

jQuery Selectors