jQuery :nth-last-child()Selector
Examples
Select <p> elements that are the third child of their parent, counting from the last child:
Try it Yourself »
Definition and Usage
:nth-last-child(n) selector selects all elements that are thennth child element of their parent, of any type, counting from the last child.
Tip:Please use:nth-last-of-type()the selector to select all elementsof any typethat are the nthnchild element of their parent, counting from the last child.
Syntax
| Parameter | Description |
|---|---|
| n | The index of each child element to match. Must be a number. The index of the first element is 1. |
| even | Selects each even child element. |
| odd | Selects each odd child element. |
| formula | Specifies which child element is selected by the formula (an + b) to select. Example: p:nth-last-child(3n+2) selects every third paragraph, starting from the second-to-last child. |
Try it Yourself - Examples
Select every <p> element that is the first child of all <div> elements, counting from the last child
How to select <p> elements that are the first child of all <div> elements, counting from the last child.
Using the formula (an + b)
How to use the formula (an + b) to select different child elements, counting from the last child.
Using "even" and "odd"
How to use even and odd to select different child elements, counting from the last child.
Differences between :nth-child(), :nth-last-child(), :nth-of-type(), and :nth-of-last-type()
Differences between p:nth-child(2), p:nth-last-child(2), p:nth-of-type(2), and p:nth-of-last-type(2).
Other Extensions
jQuery Selector