Use OnMouseOver in Javascript
There are a couple of ways to use OnMouseOver in Javascript...
If you've used
onClick or
OnMouseOut then you already know how to use the onMouseOver event handler.
You can write the javascript right into the link tag or you can
call a function located elsewhere in your code.
First, we'll write the code right into the link:
<a href="#" OnMouseOver="alert('Thanks for the onMouse!')">Need an onMouse?</a>
-After the OnMouseOver tag, we enclose our entire javascript code in double quotation marks.
-We use javascript's built-in
alert method to open an alert box. Since we are inside double quotes, we use single quotes around our message.
Using OnMouseOver to call a function is similar and fairly easy:
function sayHey() {
alert('Thanks for the onMouse!');
}
<a href="#" OnMouseOver="sayHey()">Do you need an onMouse?</a>
-First we
created our function sayHey.
-Instead of writing our code in the OnMouseOver tag, we just called our newly created function.
Note: An older version of Firefox for Mac hung after executing onMouseOver. It works fine on 2.0.0.12.
Free Copy and Paste Javascript Code:
<script type="text/javascript">
<!--
function sayHey() {
alert('Thanks for the onMouse again!');
}
-->
</script>
<a href="#" OnMouseOver="alert('Thanks for the onMouse!')">On Mouse 1</a>
<a href="#" OnMouseOver="sayHey()">On Mouse 2</a>
Resources:
Use onClick in Javascript
Create a Function in Javascript
Call your Function in Javascript
Opening an Alert Box in Javascript