jQuery Tutorial Tutorials - jQuery :nth-of-type() selector

:nth-of-type() selector

The 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.

jQuery :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)')

jQuery :nth-of-type() selector Examples

In below example,We will hightlight each p element that is third in relation to its sibling p.

Try now

Date:2019-08-18 13:01:24 From:www.Lautturi.com author:Lautturi