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>
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>
Share
Improve this question
edited Jan 1, 2017 at 17:24
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Dec 30, 2013 at 16:34
user2631534user2631534
4774 gold badges9 silver badges27 bronze badges
0
2 Answers
Reset to default 8How 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";
}
http://jsfiddle/UEbCL/
it should be something like this:
document.getElementById("436").style.color="red"