jQuery –最初の子と最後の子のセレクターの例
:first-childは、親の最初の子であるすべての要素を選択するために使用されます。これは、:nth-child(1)の省略形です。
例
-
$(‘li:first-child’) – selects all elements matched by
- that are the first child of their parent.
-
$(tr:first-child’) – selects all elements matched by
that are the first child of their parent. :last-childは、親の最後の子であるすべての要素を選択するために使用されます。
例
-
$(‘li:last-child’) – selects all elements matched by
- that are the last child of their parent.
-
$(tr:last-child’) – selects all elements matched by
that are the last child of their parent. jQueryの例
最初の子関数と最後の子関数を使用して「li」背景色を動的に追加する簡単な例を示します。
jQuery first child and last child example jQuery first child and last child example
- li #1
- li #2
- li #3
- li #4
- li #5
Related
- jQuery find()の例
- jQueryでラジオボタンを選択する方法
- jQuery - CSSクラス名とIDを持つ要素を取得する方法
- jQuery empty()とremove()の例
- jQuery - セレクタの例ではない
- jQuery - 空のセレクタの例
- jQuery - クリック後に送信ボタンを無効にする方法
- jQuery next()の例
- jQueryのmouseover()とmouseenter()の違い
- jQuery - セレクタの例ではない
- jQuery - ユニバーサルセレクタの例
- jQuery - 子セレクタの例
- jQueryでラジオボタンを選択する方法
- jQuery prepend()とprependTo()の例
- jQuery - Descendantセレクタの例
- jQuery - 一般的な兄弟セレクターの例
- CSSとjQueryを使ってタブのコンテンツを非表示にする方法
- jQuery - タグ名の取得方法
- jQuery - nth-childセレクターの例
- jQuery - 子セレクタの例のみ
-