3 replies [Last post]
obay
Offline
newbie
Last seen: 12 years 35 weeks ago
Timezone: GMT+8
Joined: 2007-08-01
Posts: 4
Points: 0

mycss.css:
.menuItem {
background-color: #FFFFFF;
}

How do I get the background-color value (external stylesheet) using javascript? Because I'm trying to change the background-color onMouseOver, then revert to original color onMouseOut:

onMouseOver = "this.style.backgroundColor = '#000000';" onMouseOut = "this.style.backgroundColor = '#FFFFFF';"

i.e. in the onMouseOut, i don't want to have to manually input the color which in the first place is found in the stylesheet.

i've tried using .menuItemHover, and changed classes onMouseOver/onMouseOut but cancelled that idea cos i found it too difficult and confusing.

any suggestions?? Sad

Tags:
Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 7 years 27 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

Check out the

Check out the window.computedStyle() method (non-IE) and [element].currentStyle object (IE) at the various browser, DOM & javascript references around the net. Personally, I'd recommend searching out a javascript toolkit that provides a single cross-browser interface to these details.

This page shows how to access the properties in your own javascript ... http://www.elektronaut.no/articles/2006/06/07/computed-styles

However, you may simply need to do

onmouseout = "this.style.backgroundColor = ''";

This will remove the background property from the inline style object and let the browser recalculate the background colour using the normal style cascade.

obay
Offline
newbie
Last seen: 12 years 35 weeks ago
Timezone: GMT+8
Joined: 2007-08-01
Posts: 4
Points: 0

Thanks Chris!! very

Thanks Chris!! very helpful!!!!

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 2 weeks 3 hours ago
Joined: 2004-06-30
Posts: 9668
Points: 801

OT

<punted over to off-topic>

Verschwindende wrote:
  • CSS doesn't make pies