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,438
  • 68
  • 55
  • 126
Ashwin
  • 11,453
  • 31
  • 108
  • 179
  • 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.
  • 165,803
  • 30
  • 257
  • 277
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,462
  • 11
  • 21