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 276 times
1

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 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.
- 171,639
- 30
- 264
- 288
-
-
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,482
- 12
- 23