onmouseover='src="img1.gif
or
onmouseover='this.src="img
Both would work if you have focus on the element where you have this script.
onmouseover='this.src="img
Main Topics
Browse All TopicsI just realized that when I assign a function to an event, I've been randomly using either,
onmouseover='src="img1.gif
or
onmouseover='this.src="img
and either of them work just fine
Are there any differences in those two?
I see more people are using this.src=..., are there any problems with just doing src=...
I had posted exactly the same question at http://www.experts-exchang
What Zvonko said in there is not quote true since it still works when I had a global variable named src...
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi,
I've only had 1 mug of espresso so far, so the following may be somewhat disorganized :)
As you may have noticed, both IE & FF handle "src" & "this.src" in the same manner because of the reason stated by sognoct (above). Essentially, 'this' relates to whatever you are referring. In your case, 'this' refers to the mousedover's image source. Since javascript assumes 'this', there is no functional difference.
Wat Zvonko said about global variables & naming conventions is true (but not fully explained). If you have two variables with the same name (whether one is a keyword or not) and one is declared global & the other local, you will not always end up with the results expected.
Local variables lose their scope (die/cease to exist) when they leave the function; global variables retain their values until explicitly changed.
Older browsers tended to confuse keywords & variable names under certain conditions, which made the usage of 'this' popular.
this.src and src are only equivalent on elements that have a src property, otherwise this.src will set the property on the element and src will set the property on the window object.
For instance:
<img onmouseover="foo='bar';" onmouseout="alert(this.foo
- doesn't work because foo is assigned to the window object, not the img element.
And:
<img onmouseover="this.foo='bar
- does work! (not tested *every* browser though)
I think it's better practice to be explicit and always use 'this' in event handlers, to avoid accidental scope-leak at least.
--
Lee
Business Accounts
Answer for Membership
by: sognoctPosted on 2007-12-05 at 02:04:49ID: 20410073
In JavaScript this always refers to the owner of the function we're executing, or rather, to the object that a function is a method of. When we define our faithful function doSomething() in a page, its owner is the page, or rather, the window object (or global object) of JavaScript.
js/this.ht ml
read there
http://www.quirksmode.org/