Is it possible to reset a table with even, odd rows after having picked a row changed it’s color?
jQuery is not an option.
I expected somthing like this to work.
.MyTable tr:nth-child(even) {background: gray}
.MyTable tr:nth-child(odd) {background: darkgray}
.bgYellow
{
background-color:yellow;
}
var rows = selectedRow.parentNode.parentNode.rows;
for(var i = 1; i < rows.length; i++)
{
rows[i].className = (i % 2 == 0) ? 'even' : 'odd';
}
selectedRow.removeAttribute('class');
selectedRow.className = 'bgYellow';
The
nth-childselectors have more specificity than.bgYellow, so even if a row has a class.bgYellowit will get its background from one of thenth-childselectors.Just give it more specifity,
tr.bgYellowis enough: http://jsfiddle.net/Ya4G7/2/