Once the user clicks on a link, or moves the mouse over it, JavaScript sends a link event. A link event is called onClick, which is sent only when the user clicks it. Another type is called onMouseOver, which is sent when the user moves the mouse to it.
You can use these events to affect what users see.
The first interesting thing is that there is no <script> tag. This is because anything that appears in onClick and onMouseOver quotes is understandable for JavaScript. In fact, the quotes before the end of the sentence allow you to write JavaScript into a line. You can put the entire JavaScript program in a quote in an onClick, but it will look ugly.
Please see the first line:
<a href="#" onClick="alert('Ooo, do it again!');">Click on me!</a>
This is like a formal positioning tag, but it has the magic onClick="" which means "run JavaScript in the quotes when someone clicks on the link" Note that there is a semicolon after alert.
Also note that there is nothing in the quotes of href="", which means that although there is a link, it won't go there when you click.
The next line is:
<a href="#" onMouseOver="alert('Hee hee!');">Mouse over me!</a>
This is like the first line, just using onMouseOver instead of onClick.
Now that we have finished learning the link event, please enter the wonderful picture alternation!
Previous page1234567Next pageRead the full text