View Full Version : Resolved Td background

01-18-2012, 08:00 PM

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.

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

01-18-2012, 08:08 PM
if (x == 1) {

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

<script type = "text/javascript">

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


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.

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

- Waffles