CSS: nth-child (не кроссбраузерно). Читать
тут.
javascript
:
<table id="t">
<td>1</td>
<td>2</td>
<td>3</td>
<td>3</td>
<td>2</td>
<td>1</td>
</table>
<script>
arr= document.getElementById("t").getElementsByTagName("td");
colors= ["", "blue", "red", "green"];
for (var i=0; i!= arr.length; ++i) {
arr[i].style.background=colors[arr[i].innerHTML];
}
</script>