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 wrap()の例
- jQueryでページを更新するには?
- jQuery - セレクタの例ではない
- jQuery - 子と兄弟セレクタの例
- 春のMVC - IPアドレスを使用して場所を見つける(jQuery Google Map)
- jQueryフォームセレクタの例
- jQueryを使ってツールチップを作成する方法
- jQuery - タグ名の取得方法
- jQuery - 空のセレクタの例
- jQuery - Descendantセレクタの例
- jQuery - 隣接する兄弟セレクターの例
- jQuery - 一般的な兄弟セレクターの例
- jQuery - Ajaxリクエストは200 OKを返しますが、エラーイベントは発生しますか?
- jQuery - 子セレクタの例
- jQueryに要素が存在するかどうかを調べる方法
- jQuery - CSSクラス名とIDを持つ要素を取得する方法
- jQueryのresize()の例
- jQuery - ユニバーサルセレクタの例
- jQueryキーボードイベントの例
- jQueryを使ってホバー上のテーブル行レコードをハイライト表示する方法
-