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

jQuery :last-child 選択子

jQueryの選択子

:last-child選択子を使用して、親要素の最後の子要素を選択します。

使用:first-child親要素の最初の子要素を選択するための選択子を使用します。

文法:

$(":last-child)

親の要素の最後の子要素に属するすべての<p>要素を選択する:

$(document).ready(function(){
  $("p:last-child").css("background", "coral");
});
テストをしてみる‹/›

すべての<div>要素内の最後の<p>要素を選択する:

$(document).ready(function(){
  $("div p:last-child").css("background", "coral");
});
テストをしてみる‹/›

jQueryの選択子