I have a table like this:
info1 yes no yes yes
info2 no yes no yes
info3 no yes no no
...
I could write some code (see below) that is working fine to set a green/red background if I see yes/no. But now I would like to have a different green/red for the even/odd rows.
Any idea how I can change the code below so I have different green/red for odd/even rows?
var x = document.getElementsByTagName("TD")
var i=0;
for (i=0;i<x.length;i++)
{
if (x[i].className=="tdStyle")
{
if (x[i].innerHTML=="Yes")
{
x[i].style.backgroundColor='LightCoral';
x[i].style.Color='LightCoral';
x[i].style.border='1px solid grey';
$(x[i]).html(' ');
}
if (x[i].innerHTML=="No")
{
x[i].style.backgroundColor='lightgreen';
x[i].style.Color='lightgreen';
x[i].style.border='1px solid grey';
$(x[i]).html(' ');
}
}
}
As Dhaval Marthak asked, I post js fiddle: http://jsfiddle.net/T8Xe9/