469,354 Members | 2,035 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,354 developers. It's quick & easy.

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

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.
Jul 23 '05 #1
1 3131
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.parentElemen t.id; }
if (document.all(IdString).innerText !== "") {
TempDay = Math.abs(CellToDayNumber(IdString));
if (document.all(IdString).style.backgroundColor !== "red") {
if (StartCell.length > 0) {
StartDay = TempDay; }
StartDay = Math.abs(CellToDayNumber(IdString));
StartCell = IdString;}
{ BackColor(IdString);
StartCell = "";
StartDay = 0 }}}

butchered from some code i wrote for a project

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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Tony Farrell | last post: by
reply views Thread by Diane Yocom | last post: by
3 posts views Thread by nma | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.