jQuery – n番目の子セレクターの例
jQuerynth-childは、親のntg-childであるすべての要素を選択するために使用されます。 nth-child(n)は「1-indexed」です。つまり、「n」は1からカウントされます。
たとえば、
1です。 $(‘tr:nth-child(3)’) –親の3番目の子である
2。 $(‘tr:nth-child(3n)’) –親の3番目の子ごとに
3。 $(‘tr:nth-child(even)’) –親の偶数の子である
P.S The ‘even’ and ‘odd’ are always used to create table zebra stripes effect.
jQueryの例
nth-child関数を使用してテーブル行の背景色を動的に変更する簡単な例を示します。
jQuery nth-child example jQuery nth-child example
| Row #1 |
| Row #2 |
| Row #3 |
| Row #4 |
| Row #5 |
| Row #6 |
| Row #7 |
| Row #8 |
| Row #9 |
| Row #10 |
Related
- jQuery - タグ名の取得方法
- jQuery - セレクタのサンプルが含まれています
- jQuery empty()とremove()の例
- jQuery - ユニバーサルセレクタの例
- jQuery - 子セレクタの例のみ
- jQuery - セレクタの例ではない
- jQueryでCSSクラスを動的に追加/削除する方法
- jQuery - タグ名の取得方法
- jQueryで複数の要素を選択する
- jQueryでラジオボタンを選択する方法
- jQuery - 一般的な兄弟セレクターの例
- コンテンツを表示したり非表示にするカスタムjQueryプラグインとCSS
- jQueryのmouseover()とmouseenter()の違い
- jQueryでテーブルZebra Stripesエフェクトを作成する方法
- jQuery - Descendantセレクタの例
- jQueryを使ってチェックボックスをチェック/チェック解除する方法
- jQuery - 制限付きURIへのアクセスが拒否されました - 解決策
- jQuery - タグの値または要素の内容を取得する方法
- jQuery mouseup()とmousedown()の例
- jQueryを使ってツールチップを作成する方法