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を使ってtextAreaにmaxlengthを追加する
- SpringブートAjaxの例
- jQueryを使ってチェックボックスをチェック/チェック解除する方法
- jQuery - タグ名の取得方法
- jQueryで複数の要素を選択する
- jQuery - タグの値または要素の内容を取得する方法
- jQuery - ユニバーサルセレクタの例
- jQuery - 子セレクタの例
- JQueryがInternet ExplorerのActiveXコントロールの警告にヒットしましたか? - ソリューション
- jQueryはコンテンツの表示と非表示を切り替えます
- jQueryのドロップダウンボックス値を設定する方法
- jQuery clone()の例
- jQuery - 子と兄弟セレクタの例
- jQuery - セレクタの例ではない
- jQueryフォームセレクタの例
- jQuery - 子と兄弟セレクタの例
- jQuery - Descendantセレクタの例
- jQueryのclick()とdblclick()の例
- jQuery - 隣接する兄弟セレクターの例
- jQueryで複数の要素を選択する
-