Ashwin
Ashwin

Reputation: 13537

Refering to a particular table row in html

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

Answers (2)

vityavv
vityavv

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

Alex K.
Alex K.

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

Related Questions