...

View Full Version : Passing the result of a function to onmouseover / onmouseout



IgnacioH
01-22-2005, 09:22 PM
I have the following functions:

function a()
{
var d
d="this.style.backgroundColor='#0f0'";
return d
}

function b()
{
var d
d="this.style.backgroundColor='#00f'";
return d
}

Then, inside my page, I have some divs elements that I would like to assign the onmouseover / onmouseout event with the result of the functions as arguments:

<div id="menu_bi" onmouseover="a()" onmouseout="b()">Item 1</div>


Can this be done? Haven't work for me yet.

Thanks,

Ignacio

Puffin the Erb
01-22-2005, 09:53 PM
Change your function to this:

function a(elem)
{
var d
d=elem.style.backgroundColor='#0f0';
return d
}

function b(elem)
{
var d
d=elem.style.backgroundColor='#00f';
return d
}

Change your HTML to this:

<div id="menu_bi" onmouseover="a(this)" onmouseout="b(this)">Item 1</div>

IgnacioH
01-23-2005, 01:07 AM
Thanks a lot, that did the trick! :thumbsup:

Ignacio



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum