I think he literally means by the text in the data cells. Which you could do by like...
Code:
var x = document.getElementsByTagName("td");
for (i=0; i<x.length; i++){
var b = x[i].innerHTML;
if (b=="Item"){
x[i].style.backgroundColor= "blue"
}
else if (b=="hats"){
x[i].style.backgroundColor= "red"
}
}
That would literally set the color of the rows based on their content. But javascript is for functionality. Styling should be done with css, unless the its a style you want changed when the user does something.
it would be better just to give each cell with the same inside a class with the same name like
Code:
<td class="hats">hats</td>
<td class="socks">socks</td>
<td class="hats">hats</td>
then style it with css like:
Code:
.hats {
background-color: red;
}
.socks {
background-color: blue;
}