jQuery :nth-last-of-type() seletor

❮ Seletores jQuery

Exemplo

Selecione cada elemento <p> que é o terceiro elemento <p> de seu pai, contando a partir do último filho:

$("p:nth-last-of-type(3)")

Definição e uso

O seletor :nth-last-of-type( n ) seleciona todos os elementos que são o n -ésimo filho, de um tipo específico, de seu pai, contando a partir do último filho.

Dica: Use o seletor :nth-last-child() para selecionar todos os elementos que são o n -ésimo filho, independentemente do tipo , de seu pai, contando a partir do último filho.


Sintaxe

:nth-last-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-last-child(3n+2) selects each 3rd paragraph, starting at the last 2nd paragraph

Experimente você mesmo - Exemplo


Como selecionar cada elemento <p> que é o primeiro elemento <p> de todos os elementos <div>, contando a partir do último filho.


Como usar uma fórmula ( an + b ) para selecionar diferentes elementos <p>, contando a partir do último filho.


Como usar par e ímpar para selecionar diferentes elementos <p>, contando a partir do último 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).


❮ Seletores jQuery