jQuery - nth-childセレクターの例

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