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 - タグ名の取得方法
- jQuery - ユニバーサルセレクタの例
- jQuery - 子セレクタの例のみ
- jQuery - 制限付きURIへのアクセスが拒否されました - 解決策
- jQuery - 子と兄弟セレクタの例
- jQuery - タグの値または要素の内容を取得する方法
- SpringブートAjaxの例
- jQuery - 子セレクタの例のみ
- jQueryでコピー、ペースト、カットの動作を検出する方法
- JSON文字列のjQueryループ - $. 各例
- jQuery - CSSクラス名とIDを持つ要素を取得する方法
- jQuery - 空のセレクタの例
- jQueryはコンテンツの表示と非表示を切り替えます
- JQueryはWordPressで動作していません - 解決策
- jQuery - 隣接する兄弟セレクターの例
- jQueryを使ってtextAreaにmaxlengthを追加する
- jQueryフォームセレクタの例
- jQuery - 一般的な兄弟セレクターの例
- jQuery - Descendantセレクタの例
- jQueryを使ってチェックボックスをチェック/チェック解除する方法
-