1

I have five rows in my table in html. Each row has only 1 td. I want to manipulate the table row background in a function. How do I refer to the table row in the function?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ashwin
  • 12,691
  • 31
  • 118
  • 190
  • Would using CSS (as in this [stackoverflow question][1]) meet your requirement? [1]: http://stackoverflow.com/questions/569355/html-table-row-link – teq Jan 31 '12 at 11:16

2 Answers2

1

You can reference them by their ordinal index;

var tbl = document.getElementById("myTable");
var firstRow = tbl.rows[0];
...
tbl.rows[n].style.color = "red"; 
...

https://developer.mozilla.org/en/DOM/table.rows

Alex K.
  • 171,639
  • 30
  • 264
  • 288
0

You can give it an ID and use document.getElementById("id"); or you can get it by tag name with document.getElementsByTagName("tr")[x];, where x is the number row (fifth row, x=5)

vityavv
  • 1,482
  • 12
  • 23