user2631534
user2631534

Reputation: 477

Javascript change style of td element using tr id

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

Answers (2)

bbuecherl
bbuecherl

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";
}

http://jsfiddle.net/UEbCL/

Upvotes: 8

semirturgay
semirturgay

Reputation: 4201

it should be something like this:

 document.getElementById("436").style.color="red"

Upvotes: 1

Related Questions