nV News Forums

 
 

nV News Forums (http://www.nvnews.net/vbulletin/index.php)
-   Software Development (http://www.nvnews.net/vbulletin/forumdisplay.php?f=53)
-   -   Table TD Background Color (javascript) (http://www.nvnews.net/vbulletin/showthread.php?t=94462)

technoid 07-07-07 08:37 AM

Table TD Background Color (javascript)
 
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 02:29 PM

Re: Table TD Background Color (javascript)
 
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 02:54 AM

Re: Table TD Background Color (javascript)
 
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 11:40 AM

Re: Table TD Background Color (javascript)
 
Quote:

Originally Posted by t3hl33td4rg0n
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 12:59 PM

Re: Table TD Background Color (javascript)
 
Quote:

Originally Posted by fivefeet8
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 02:18 PM

Re: Table TD Background Color (javascript)
 
What about getVariableById()?

fivefeet8 07-19-07 12:58 PM

Re: Table TD Background Color (javascript)
 
Quote:

Originally Posted by stncttr908
What about getVariableById()?

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

fivefeet8 07-19-07 01:00 PM

Re: Table TD Background Color (javascript)
 
Quote:

Originally Posted by technoid
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.


All times are GMT -5. The time now is 05:35 PM.

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.