How can I use onclick to change a table cell background color

M

Michael

How can I use onclick to change a table cell background color. I know
I can use this.className=?

to change the classname. But then I would have to put the code into
every single table cell. I read once about using a collection method.

Lets say a table has 100 TD Cells with a white background. I want to
click on just 1 and then have it change to a Yellow background. Then
when I click on a different Cell have the old one change back to white
and the new Cell change to Yellow. etc.
 
W

Woody

function BgnDay_onclick() {
var IdString = ""
var TempDay = 0
var GoodPick = true

if (DateSet == false) {
IdString = window.event.srcElement.id;
if (IdString.length < 4) {
IdString = window.event.srcElement.parentElement.id;
if (IdString.length < 4)
IdString = window.event.srcElement.parentElement.parentElement.id; }
if (document.all(IdString).innerText !== "") {
TempDay = Math.abs(CellToDayNumber(IdString));
if (document.all(IdString).style.backgroundColor !== "red") {
if (StartCell.length > 0) {
BackColor(StartCell);
StartDay = TempDay; }
RedItOut(IdString);
StartDay = Math.abs(CellToDayNumber(IdString));
StartCell = IdString;}
else
{ BackColor(IdString);
StartCell = "";
StartDay = 0 }}}
DisplayDate();

butchered from some code i wrote for a project

Woody
any sugestion or comment made by me should be examined first for
validity and appropriateness before assuming i have any idea at all
what the heck i am talking about. I am not responsible for anything you
may see with my name attached to it, i think.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top