Forum Moderators: open

Message Too Old, No Replies

CSS values into a javascript string

No idea if its even possible

         

Greven

6:40 am on Apr 4, 2005 (gmt 0)

10+ Year Member



Basicly I want to be able to take the value a specific CSS attribute and print it to a string. Maybe an example would be more explanatory:

I have a CSS file that sets value for various attributes on different elements. In this case, the elements themselves do not exist in the HTML file, but if need be I can put them in and wrap with with a "display: none" div. What I'm trying to do is, for example, take an element and try to access the value of a style settings in such a way:

document.config.tablebg.value = document.getelementbyid("quicklinktable").style.backgroundColor;

I've tried backgroundColorname, but its undefined when the color is set in the CSS file as "red". I don't know if this is even possible, the ultimate goal is to have the input fields default to the current setting.

johnl

7:02 am on Apr 4, 2005 (gmt 0)

10+ Year Member



hi,
if you are coding in javascript, you might be looking for the methods
element.getAttribute and element.setAttribute
and
element.getComputedStyle.

Bernard Marx

7:15 am on Apr 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



getComputedStyle isn't supported by IE.
IE uses the non-standard, but much more straightforward, currentStyle property.

document.getelementbyid("quicklinktable").currentStyle.backgroundColor

johnl

7:22 am on Apr 4, 2005 (gmt 0)

10+ Year Member



non-standard?
who is interested in non-standards?

;-)

Bernard Marx

8:08 am on Apr 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Free thinkers and anarchists.

johnl

10:58 am on Apr 4, 2005 (gmt 0)

10+ Year Member



hi bernard,
i stand corrected.
johnl