Forum Moderators: open

Message Too Old, No Replies

Changing <TD>,<TR>, and <TABLE> background colors

I need to know how to change the background color of these tags

         

HelpAN00b

5:17 am on Dec 12, 2004 (gmt 0)

10+ Year Member



Hey, I'm relativley new to javascript, without that many resources, and i was wondering what object you use to change the bahe background color of <TD>, <TR>, and <TABLE>.

Thanks in advance.

orion_rus

8:03 am on Dec 12, 2004 (gmt 0)

10+ Year Member



To answer this we need something more information about of condition changing
Simple script if u want to change it if u clicks on a object seems like so:

<tr>
<td onclick="this.style.backgroundColor=#FF0000;">Change Background</td>
</tr>

or something like this
good luck to you

kaled

9:33 am on Dec 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<td id="test1">some text</td>

<script>
var tmp = document.getElementById('test1');
if (tmp) {
tmp.style.backgroundColor = '#FF0000'; // red background
tmp.style.color = '#008000'; // green text
}
</script>

It should be possible to change styles for tables and table cells, however, if you wish to change styles for table rows, you should test browser compatibility.

Kaled.