I want to be able to click a table cell, have it switch to color1, and then on the next click have it switch to color2, then back to color1… and so on.
function cSwap(cell){
if (cell.style.backgroundColor = "#00000F")
{
cell.style.backgroundColor = "#F00000";
}
else if (cell.style.backgroundColor = "#F00000")
{
cell.style.backgroundColor = "#00000F";
}
}
Right now, it only changes to the first color, and subsequent clicks do nothing.
The cells of the table each look like this:
<td classname='t' onclick='cSwap(this);' width='100' height='100' id='nw'><a href="" id="nw"></a></td>
…which’ll be CSS once I get everything working (beside the point).
Even with double equal signs it won’t work.
backgroundColorwill change its string to anrgbvalue in Firefox when its value is retrieved (and other browsers may behave alike).A solution is to put those colors in a class and switch the table cell’s class on click. That’s also more general, as you can easily change the colors.
CSS:
Also, the attribute is called
class, notclassname. And remember that you cannot have two elements with the same ID:And the accompanying script: