jQuery :nth-last-child() seletor

❮ Seletores jQuery

Exemplo

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

$("p:nth-last-child(3)")

Definição e uso

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

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


Sintaxe

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

Experimente você mesmo - Exemplo


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


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


Como usar par e ímpar para selecionar diferentes elementos filho, 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