/    Sign up×
Community /Pin to ProfileBookmark

change onmouseover() target function

Hi

I have an onmouseover attribute which calls a function called changePicture, and it works fine, by changing the src of the picture.

If I mouse over something else I want to call a function to change the target of the onmouseover attribute declared before.

I want it to call another function, not the changePicture() declared before.

Is this possible?

I am not using JQUERY or similar.

Thanx

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@tirnaAug 16.2010 — Maybe use this as a guide:

[code=php]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
<!--

function changePicture() {
alert('Function changePicture was called');
}

function changeFunction(elemId) {
document.getElementById(elemId).onmouseover=function() {
alert("This is div1's new function");
}
alert("div1's onmouseover function has been changed");
}

//-->
</script>

</head>
<body>

<div id="div1" style="width: 100px;" onmouseover="changePicture();">
This is Div 1
</div>

<div id="div2" style="margin: 50px 0px 0px 100px; width: 100px" onmouseover="changeFunction('div1');">
This is Div 2
</div>

</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@giovanni_85authorAug 16.2010 — thanks a lot!

this is exactly what I was looking for!

It works perfectly!
Copy linkTweet thisAlerts:
@tirnaAug 16.2010 — no problem - you're welcome ?
×

Success!

Help @giovanni_85 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...