jQuery :first-child セレクタ

❮ jQuery Selectors

親の最初の子である全ての <p> 要素を選択する:

$("p:first-child")
Try it Yourself »

定義と用法

:first-child セレクタは、それぞれの親に対する最初の子である全ての要素を選択します。

チップ: それぞれの親に対する最後の子である全ての要素を選択するには、 :last-child セレクタを使用します。


構文

$(":first-child")

Try it Yourself - 例

全 <div> 要素における最初の <p> 要素を選択
全ての <div> 要素における最初の <p> 要素を選択する方法。

:first と :first-child との違い
:first と :first-child セレクタとの違いを示します。

:first、:first-child、:first-of-type との違い
:first、:first-child、:first-of-type セレクタの違いを示します。


❮ jQuery Selectors