jQuery Tutorial Tutorials - jQuery :nth-child() selector

:nth-child() selector

The jQuery :nth-child() selector is used to select all elements that are the nth-child of their parent.The index of childrens start with 1.

jQuery :nth-child() selector Syntax

$(':nth-child(index/even/odd/equation)')
selector description
$(':nth-child(3)') get the third child element
$(':nth-child(odd)') get the child elements which index is 1,3,5 etc
$(':nth-child(even)') get the child elements which index is 2,4,6 etc
$(':nth-child(3n)') get the child elements which index is 3,6,9 etc
$(':nth-child(2n+1)') same as $(':nth-child(odd)')

jQuery :nth-child() selector Examples

In below example,We will hightlight third p in each div.

Try now

Date:2019-08-18 12:49:06 From:www.Lautturi.com author:Lautturi