Easy Tutorial
❮ Misc When Html Hasclass ❯

jQuery :nth-child() Selector

jQuery Selectors

Example

Selects every <p> element that is the third child of its parent:

$("p:nth-child(3)")

Definition and Usage

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

Tip: Use the :nth-of-type() selector to select all elements that are the nth child of a particular type of their parent.


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-child(3n+2) selects every third paragraph, starting from the second child element.

Try It - Examples

Select every <p> element that is the second child of a <div> element

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

Use "even" and "odd"

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


jQuery Selectors

❮ Misc When Html Hasclass ❯