Reputation: 1981
I'm new b to JS, any help would be appreciated
have following code
<head>
<script language="Javascript">
function my(eve)
{
// Internet Explorer
if (eve.srcElement)
{
alert(eve.srcElement.nodeName);
}
// Netscape and Firefox
else if (eve.target)
{
alert(eve.target.nodeName);
}
};
</script>
</head>
<body onmousemove="my(eve);">
//Some HTML code
</body>
Getting Error in FF Console while moving mouse over the browser window-
"ReferenceError: eve is not defined
my(eve);"
Upvotes: 0
Views: 1164
Reputation: 150030
You probably meant to do this:
<body onmousemove="my(event);">
That is, you wanted to pass the event
object to your my()
function. Then within that function you can refer to it by the eve
variable. (Note that it is very common to define an event variable with the name e
rather than eve
- a matter of preference, it'll work either way.)
Also your closing script tag is incorrect, you should have </script>
not <script>
.
Working demo: http://jsbin.com/oyoqeg/1/edit
(Note that displaying an alert on mousemove makes the page pretty much unusable, but that's another issue.)
Upvotes: 3
Reputation: 28837
You have to define "eve" first. If eve is text you should use my('eve')
, if eve is a variable you need to define it first with var eve =... ;
Otherwise if you might want to use event
or this
. my(event)
or my(this)
.
Upvotes: 2