Use OnMouseOver in Javascript
There are a couple of ways to use OnMouseOver in Javascript...
If you've used
onClick, then you already know how to use onMouseOver.
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="javascript:alert('Thanks for the onMouse!')">Need an onMouse?</a>
-After the OnMouseOver tag, we enclose our entire javascript code in double quotation marks.
-We start with the
javascript: to tell the browser we have javascript code coming up.
-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="javascript: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: I don't know why, but Firefox for Mac hangs after executing onMouseOver. You can't back up or click on anything in the browser window. Safari for Mac and Windows IE and Firefox tested okay.
Free Copy and Paste Javascript Code:
<script type="text/javascript">
<!--
function sayHey() {
alert('Thanks for the onMouse again!');
}
-->
</script>
<a href="#" OnMouseOver="javascript:alert('Thanks for the onMouse!')">On Mouse 1</a>
<a href="#" OnMouseOver="javascript: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
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
| | | CSS David McFarland |
| | | |
| | | |