I have very simple code and I am not sure why the Foo function is not fired when the mouse is over the image:
here <img id="sss" alt="some image" onmouseover="Foo(this);" src="https://www.google.com/intl/en_com/images/srpr/logo3w.png" width="16" height="16" />
<div onmouseover="Foo(this);">
THIS IS DIV
</div>
function Foo(obj)
{
alert('s');
}
UPDATE 1:
What actually happens is that I create the image element dynamically and then add it to the page. The Foo function is already inside the JS file but it never gets called.
The code you have currently is correct, as this fiddle shows. I’m guessing your problem is that Foo is not global on your page.
Also, instead of passing
thisas a parameter to your function, you can set it as the this value inside of your function by usingcallFinally, consider changing
Footofoo, since functions starting with capital letters usually denote constructors in JavaScript.