Reputation: 477
I have one table:
<table>
<tr id="436">
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>
Now I need using Javascript to get tr element using id and then in that tr add CSS style of changing text color.
I have try getelementbyid("436")
but I don't know how to do next.
So I need to get this:
<table>
<tr id="436">
<td style="color: red">1</td>
<td style="color: red">2</td>
<td style="color: red">3</td>
</tr>
</table>
Upvotes: 3
Views: 31917
Reputation: 1619
How about this, if you really want to change the color of the td
elements:
var tr = document.getElementById("436");
var tds = tr.getElementsByTagName("td");
for(var i = 0; i < tds.length; i++) {
tds[i].style.color="red";
}
Upvotes: 8
Reputation: 4201
it should be something like this:
document.getElementById("436").style.color="red"
Upvotes: 1