jQuery :nth-​​last-of-type()セレクター

❮jQueryセレクター

最後の子から数えて、親の3番目の<p>要素である各<p>要素を選択します。

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

定義と使用法

:nth-​​last-of-type(n )セレクターは、最後の子から数えて、親の特定のタイプのn番目の子であるすべての要素を選択します。

ヒント::nth-last-child()セレクターを使用して、親のタイプに関係なく、最後の子から数えてn番目の子であるすべての要素を選択します。


構文

: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

自分で試してみてください-例


て選択します。すべての<div>要素の最初の<p>要素である各<p>要素を選択する方法。最後の子から数えます。

使用
、最後の子から数えて、さまざまな<p>要素を選択する方法。


の使用最後の子から数えて、偶数と奇数を使用して異なる<p>要素を選択する方法。


の違いp:nth-​​child(2)、pの違い:nth-​​last-child(2)、p:nth-​​of-type(2)およびp:nth-​​of-last-type(2)。


❮jQueryセレクター