...

View Full Version : Resolved Td background



Waffles32
01-18-2012, 08:00 PM
Hi,

I have tried to figure this out but haven't had any luck..

I need a td (id="td1") to have a bgcolor of black when a variable is equal to 1.
So:

var x = equation that is equal to 1;
if (x == 1) {
Code to make td have a black bg;
} else { Don't change anything.}

I am stuck because all the resources that I could find are talking about td:hover CSS.

- Waffles

xelawho
01-18-2012, 08:08 PM
if (x == 1) {
document.getElementById("td1").style.backgroundColor="#000000"
}

Philip M
01-18-2012, 08:12 PM
<table>
<tr>
<td id = "td1">Some Text Here
</td>
</tr>
</table>

<script type = "text/javascript">

var x = 1;
if (x==1) {
document.getElementById("td1").style.backgroundColor = "black"
}

</script>

If your styling is more complicated than that, you should define a css class and change the className as appropriate.

Quizmaster: What is the English translation of the French word voiture?
Contestant: A tree.

Waffles32
01-18-2012, 08:20 PM
Thank you both very much!
My page is working smoothly now and it looks great!

- Waffles



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum