Selector jQuery :nth-of-type()
Ejemplo
Seleccione cada elemento <p> que sea el tercer elemento <p> de su padre:
$("p:nth-of-type(3)")
Definición y uso
El selector :nth-of-type( n ) selecciona todos los elementos que son el nth hijo, de un tipo particular, de su padre.
Sugerencia: use el selector :n-th-child() para seleccionar todos los elementos que son el n -ésimo hijo, independientemente del tipo , de su padre.
Sintaxis
: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 |
Pruébelo usted mismo - Ejemplo
Cómo seleccionar cada elemento <p> que sea el segundo elemento <p> de todos los elementos <div>.
Cómo usar una fórmula ( an + b ) para seleccionar diferentes elementos secundarios.
Cómo usar pares e impares para seleccionar diferentes elementos secundarios.
La diferencia entre p:nth-child(2), p :nth-last-child(2), p:nth-of-type(2) y p:nth-of-last-type(2).