jQuery :nth-of-type() seletor
Exemplo
Selecione cada elemento <p> que é o terceiro elemento <p> de seu pai:
$("p:nth-of-type(3)")
Definição e uso
O seletor :nth-of-type( n ) seleciona todos os elementos que são o n -ésimo filho, de um tipo específico, de seu pai.
Dica: Use o seletor :nth-child() para selecionar todos os elementos que são o n -ésimo filho, independentemente do tipo , de seu pai.
Sintaxe
:nth-of-type(n|even|odd|formula)
Parameter | Description |
---|---|
n | The index of each child to match. Must be a number. The first element has the index number 1. |
even | Selects each even child element |
odd | Selects each odd child element |
formula | Specifies which child element(s) to be selected with a formula (an + b). Example: p:nth-of-type(3n+2) selects each 3rd paragraph, starting at the 2nd paragraph |
Experimente você mesmo - Exemplo
Como selecionar cada elemento <p> que é o segundo elemento <p> de todos os elementos <div>.
Como usar uma fórmula ( an + b ) para selecionar diferentes elementos filho.
Como usar par e ímpar para selecionar diferentes elementos filho.
A diferença entre p:nth-child(2), p :nth-last-child(2), p:nth-of-type(2) e p:nth-of-last-type(2).