jQuery :nth-child() seletor
Exemplo
Selecione cada elemento <p> que é o terceiro filho de seu pai:
$("p:nth-child(3)")
Definição e uso
O seletor :nth-child( n ) seleciona todos os elementos que são o n -ésimo filho, independentemente do tipo, de seu pai.
Dica: Use o seletor :nth-of-type() para selecionar todos os elementos que são o n -ésimo filho, de um tipo específico , de seu pai.
Sintaxe
:nth-child(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-child(3n+2) selects each 3rd paragraph, starting at the 2nd child element |
Experimente você mesmo - Exemplo
Como selecionar cada elemento <p> que é o segundo filho 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).