Easy Tutorial
❮ Sel Input Password Sel Input Reset ❯

jQuery :nth-last-child() Selector

jQuery Selectors

Example

Select the <p> element that is the third child of its parent, counting from the last child:


Definition and Usage

The :nth-last-child(*n*) selector selects all elements that are the nth child of their parent, of any type, counting from the last child.

Tip: Use the :nth-last-of-type() selector to select all elements that are the nth child of their parent, of any type, counting from the last child.


Syntax

Parameter Description
n The index of each child element to match. <br> <br> Must be a number. The first element has an index of 1. <br>
even Selects every even child element.
odd Selects every odd child element.
formula Specifies which child elements to select using the formula (an + b). <br> Example: p:nth-last-child(3n+2) selects every third paragraph, starting from the second-to-last child.

Try It - Examples

Select every <p> element that is the first child of a <div> element, counting from the last child

Select different child elements using the formula (an + b)an +b ) from the last child.

Use "even" and "odd"

Differences between :nth-child(), :nth-last-child(), :nth-of-type(), and :nth-of-last-type()


jQuery Selectors

❮ Sel Input Password Sel Input Reset ❯