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.
Table of Contents
Selecting the nth child with jQuery and JavaScript
Syntax for nth child (JS/jQuery)
:nth-child(n | even | odd | formula)
Parameter | Description |
n | Index of child element. The first element has index 1 and not 0. |
even | Selects each even child in the parent element. |
odd | Selects each old child |
formula | Specifies which child element to be selected with formula an+b |
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.