View Full Version : onmouseover to change bg

02-03-2004, 08:36 AM
I'm trying to use an onmouseover to change the background of one of my <div> statements, but it doesn't seem to work. Here's my line of code:

<div id="button1" style="background-color: #7f25a7; position: absolute; width: 44px; height: 41px; top: 331 px; left: 80px;">
<table width="100%" height="100%">
<td align="center"> <font color="#000000" size="2"><strong><a href="film.asp" onMouseOver="document.getElementById('button1').style.background-color = '#C338FF'">Film</a></strong></font>


02-03-2004, 12:04 PM
Hi there jgallen,

When using javascript you have to change the
css attributes in this manner....

background-color becomes backgroundColor
border-color becomes borderColor
font-size becomes fontSize



02-03-2004, 12:51 PM
Unless of course you use cssText but I'm not sure how crossbrowser that is.

*moving to javascript*

02-03-2004, 01:20 PM
The problem with changing the background like that is that IE and NS handle the style attribute differently. In NS if you want to access an objects style properties its written document.getElementById('button1').backgroundColor however in IE you access it similiar to how you've written it document.getElementById('button1').style.backgroundColor

02-03-2004, 02:04 PM
Well, that was nn4. In Mozilla or browsers based on it (ns6+, Mozilla Firebird, Camino, Galeon, K-Melon etc.), in Opera 7 or in khtml based browsers such as Apple Safari, OmniWeb or Konqueror you use the style property to set styles. In iem and iew you do it that way as well.

02-03-2004, 05:57 PM
netscape doesn't use position:absolute does it? because I looked at the page in netscape and it looks pretty messed up

02-03-2004, 06:47 PM
What browser do you mean by "netscape"? Nn4? Ns6? Ns7? Moz?
They all support absolute positioning, but nn4 is quirkier than any other browser.