jquery の 1 つのテーブル行の色を赤に変更し、リストされている他のすべての行を白に設定できるようにする必要があります。
それぞれにクラスを設定しまし<tr class=row1>
た<tr class=row2>
。色を付ける必要がある現在の行 ID の JavaScript 変数はid
.
ここからどこへ行けばいいですか?
$('table tr').eq( ).css({color:'red'}).siblings().css({color:'white'});
// ^^-- set here the index number of the row you desire to change color
$('tr:eq(0)', 'table')
.siblings('color', '#fff') // select all tr except first one and change color
.andSelf() // target to the first one
.css('color', '#f00'); // change color of first tr
:eq(index)
ターゲット要素に応じて、内のインデックスを変更できます。
私はcssを使用することをお勧めします、
たとえば、class="row1" で 3 行を赤に設定する場合は、
.row1:nth-child(3){
background-color: red;
}