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

jQuery :first-of-type選択子

jQueryの選択子

:first-of-type選択子は、親要素の特定のタイプの最初の子要素を持つすべての要素を選択します。

これは:nth-of-type(1)と同じです。

使用:last-of-type選択子は、親要素に属する特定のタイプの最後の子要素を選択できます。

语法:

$(":first-of-type")

親の要素内の最初の<p>要素に属するすべての<p>要素を選択します:

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

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

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

jQueryの選択子