:nth-of-type()
selectorThe jQuery :nth-of-type()
selector is used to select all elements that are the nth child of their parent in relation to siblings with the same element name.
:nth-of-type()
selector Syntax$(':nth-of-type(index/even/odd/equation)')
selector | description |
---|---|
$(':nth-of-type(3)') |
get the third child element with specifiled type |
$(':nth-of-type(odd)') |
get the child elements with specifiled type which index is 1,3,5 etc |
$(':nth-of-type(even)') |
get the child elements with specifiled type which index is 2,4,6 etc |
$(':nth-of-type(3n)') |
get the child elements with specifiled type which index is 3,6,9 etc |
$(':nth-of-type(2n+1)') |
same as $(':nth-of-type(odd)') |
:nth-of-type()
selector ExamplesIn below example,We will hightlight each p element that is third in relation to its sibling p.