Forum Moderators: open

Message Too Old, No Replies

Changing DIV class/style

         

porcelinaoceans

12:39 pm on Jul 9, 2003 (gmt 0)



Is it possible to change a DIV's class/style (especially its filter) on a onmouseover / onclick event?
Here is the url of my test page:
<sorry, no test page links>
any help would be appreciated.
many thanks,
davey

[edited by: tedster at 1:24 pm (utc) on July 9, 2003]

moonbiter

2:16 pm on Jul 9, 2003 (gmt 0)

10+ Year Member



Sure. All you have to do is to write a script function that changes the className property of the div element in question. You would then specify all of your styles on the classes with css. Something like:

(css)
.one { background: #FFF; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100)}
.two { background: #000; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=50) }

(script)

function changeClass(newClassName,targetDiv) {
targetDiv.className = newClass;
}

(html)

<div onmouseover="changeClass('two',this)" class="one"></div>

is a straightforward way to get it to work.

There are more elegant ways of putting the event handler on the div, but I will leave that as an exercise.