English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery :nth-last-of-type() 選択子

jQuerの選択子

:nth-last-of-type()選択子は、同じ階層の兄弟要素の中での位置(末尾から数えて)に基づいて指定された種類の全ての要素を選択します。

使用:nth-last-child()選択子要素の種類が限定されない親要素の第 n 個の子要素を持つ全ての要素を選択します。カウントは最後の子要素から行われます。

文法:

$(":nth-last-of-type(number|An+B|odd|even)

親要素の末尾から、その親要素に属する4個<span>要素の各<span>要素:

$("document").ready(function(){
  $("span:nth-last-of-type(4)").css("background", "lime");
});
テストを試してみて‹/›

奇数と偶数のキーワードは、インデックスが奇数または偶数の子要素に一致する場合に使用されます:

$("document").ready(function(){
  $("span:nth-last-of-type(odd)").css("background", "lime");
  $("span:nth-last-of-type(even)").css("background", "aqua");
});
テストを試してみて‹/›

パラメータ値

パラメータ説明
number一致する子要素の各インデックス(1開始)
odd奇数の各子要素を選択
even偶数の各子要素を選択
An+B選択する子要素を指定
例:p:nth-last-of-type(3n + 2)第2段から、次の各第3段を選択

jQuerの選択子