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

❮jQueryセレクター

親の3番目の<p>要素である各<p>要素を選択します。

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

定義と使用法

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

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


構文

: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

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


各<p>要素を選択する方法。

使用
さまざまな子要素を選択する方法。


の使用偶数と奇数を使用して異なる子要素を選択する方法。


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


❮jQueryセレクター