:nth-child()
selectorThe 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.
: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)') |
:nth-child()
selector ExamplesIn below example,We will hightlight third p in each div.