How to get nth child with jQuery and JavaScript

In this blog we will be discussing how to get nth child using jQuery and JavaScript. In jQuery, :nth-child() Selector selects all the elements that are the nth-child of their parent element, regardless of the type of the parent element.

Selecting the nth child with jQuery and JavaScript

Syntax for nth child (JS/jQuery)

:nth-child(n | even | odd | formula)
ParameterDescription
nIndex of child element. The first element has index 1 and not 0.
evenSelects each even child in the parent element.
oddSelects each old child
formulaSpecifies which child element to be selected with formula an+b
Parameter description for selecting the nth-child

Examples & Demo for nth-child Selection with JS

Let’s look at an example to understand better.

See the Pen Untitled by Arpit Mittal (@codingiseasy) on CodePen.

Hope the article was informative and you got to learn something new. Comment below in case you have any queries.

Leave a Comment