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

jQuery :first-child選択子

jQueryの選択子

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

次に:last-child親の最後の子の要素を選択する選択子を指定します。

構文:

$(":first-child)

親の最初の子のすべての<p>要素を選択します:

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

すべての<div>要素内の最初の<p>要素を選択します:

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

jQueryの選択子