PDA

View Full Version : Table TD Background Color (javascript)


technoid
07-07-07, 07:37 AM
What I want to do is read the background color of a table td element, then add 101010 to it to lighten it up and then write that value to it. So far I can write a value but when I try to read it I don't get the value. I thought the background color was read/write.

I can set the color this way.

var bgclr = "#cccccc";
this.style.backgroundColor=bgclr;

But I can't read the color with this.

var bgclr=this.style.backgroundColor;

The initial background color is set in the css class.

EDIT: If I set the background color using an in-line style the read works correctly. But if I use an external css class it doesn't.

fivefeet8
07-11-07, 01:29 PM
I remember running into the same situation with a scheduling web app I created. It seems the background color attribute is only accessible if it's inline.

t3hl33td4rg0n
07-12-07, 01:54 AM
Hmm, that is odd... Are you running this on IIS or Apache? I know IIS has had problems when calling external CSS stylesheets, I don't know why, but when I switched to Apache, problem went away.

You could try calling the stylesheet before the script. Thats all I have for now :headexplode:

fivefeet8
07-18-07, 10:40 AM
Hmm, that is odd... Are you running this on IIS or Apache? I know IIS has had problems when calling external CSS stylesheets, I don't know why, but when I switched to Apache, problem went away.

You could try calling the stylesheet before the script. Thats all I have for now :headexplode:

If he's using javascript to modify the CSS attribute, then it's on the client side. Either it's something with javascript or it's the browser. Remember, CSS and javascripts are cached locally on the client's computer.

technoid
07-18-07, 11:59 AM
If he's using javascript to modify the CSS attribute, then it's on the client side. Either it's something with javascript or it's the browser. Remember, CSS and javascripts are cached locally on the client's computer.
Yes, I'm using javascript to modify it. I gave up trying to do a read/modify/write and just created two classes and changed the class using javascript.

stncttr908
07-18-07, 01:18 PM
What about getVariableById()?

fivefeet8
07-19-07, 11:58 AM
What about getVariableById()?

Isn't that a flash proprietary function? It's not listed in the default Javascript function list.

fivefeet8
07-19-07, 12:00 PM
Yes, I'm using javascript to modify it. I gave up trying to do a read/modify/write and just created two classes and changed the class using javascript.

Why didn't you use the inline CSS as that worked right? Then you could create a Javascript variable to hold the background color at runtime and modify it any way you like afterwards. You could also try accessing the CSS file directly with javascript and modify the CSS class directly instead of from a HTML element style.