/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] DOM object, new Function: img src is syntax error?

I am trying to create a mouseover routine this way:

[code]
ClImg1 = new Image(); ClImg1.src=”/var/www/html/images/redlight.png”;
ClImg2 = new Image(); ClImg2.src=”/var/www/html/images/greenlight.png”;

[…]

this.climg = document.createElement(“img”);
this.climg.src = ClImg1.src;
this.climg.onmouseover = new Function (this.climg.src = ClImg2.src);
[/code]

when this runs I get a syntax error from firebug, citing the ClImg2.src (not 1.src, tho) — “http://localhost/var/www…” etc

How am I suppposed to do this [I]properly?[/I] I imagine I am already wrong to call new Function from mouseover but this:

[code]
this.mousefunc = new Function (“this.climg.src = ClImg2.src”);
this.climg.onmouseover = this.mousefunc;
[/code]

gives me “this.climg.src not defined”?

A couple of lines of code from someone and I’ll be fine. Also: what’s the syntax for including parameters to this.mousefunc?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangApr 14.2009 — this.climg.onmouseover = function(){this.src = ClImg2.src;};
Copy linkTweet thisAlerts:
@akashiraffeeauthorApr 14.2009 — [edit] whoops!

Thanks Fang, that works.
×

Success!

Help @akashiraffee 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...