Reputation: 13537
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?
Upvotes: 1
Views: 729
Reputation: 1490
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
)
Upvotes: 0
Reputation: 175816
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
Upvotes: 1