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?
Asked
Active
Viewed 147 times
1
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 Answers
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";
...
Alex K.
- 165,803
- 30
- 257
- 277
-
-
Yes, you can use a number, [0] is the first row, [1] the seconds and so on. – Alex K. Jan 31 '12 at 11:25
-
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