Closed Thread Icon

Topic awaiting preservation: javascript super-rookie. Pages that link to <a href="https://ozoneasylum.com/backlink?for=27031" title="Pages that link to Topic awaiting preservation: javascript super-rookie." rel="nofollow" >Topic awaiting preservation: javascript super-rookie.\

 
Author Thread
Gilbert Nolander
Maniac (V) Inmate

From: Washington DC
Insane since: May 2002

posted posted 11-21-2005 20:17

Hello,
I am not to good at javasript, and I have tried, but I can not figure this out.

I have a .js menu. Within it there is a variable I want to set to match a color in my css code.
The javascript variable line looks like this:

code:
var LowBgColor='000000'



The CSS that I want the above variable to match, looks like this:

code:
.button  {background-color:#56A7A7}



I want the attribute from the css ".button", called "background-color" to be read by the javascrpt variable. What do I need to substitute in the javascript '000000' to make it read the css file?

The reason for this, is that I have multiple stylesheets, and I want it to read the variable from each individual stylesheet.

Thanks

----| Asylum Quotes

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-21-2005 21:49

This actually isn't very easy. Unfortunately when you don't explicitly set a CSS value via Javascript or an inline style, when you access the style via Javascript the variable is blank so:

bgcolor = document.getElementById('mybutton').style.backgroundColor

Doesn't work, you need to actually parse the sheet

Check out This tute





.:[ Never resist a perfect moment ]:.

(Edited by bitdamaged on 11-21-2005 21:56)

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 11-21-2005 22:37

You should try something like : Simon Willison : getElementBySelector or Dean Edwards : cssQuery, to get a collection of objects matching a CSS Selector, then pick one of them and pick its style.backgroundColor property.

Gilbert Nolander
Maniac (V) Inmate

From: Washington DC
Insane since: May 2002

posted posted 12-02-2005 20:48

Thanks guys.
I figured it out...

----| Asylum Quotes

« BackwardsOnwards »

Show Forum Drop Down Menu