For standard HTML attribute information about the <A> element, see the <A> topic.

The Anchor element (the essence of HTML), currently supports three distinct scripting event handlers.

OnMouseOver
The OnMouseOver event can be used to execute a script function when the mouse passes over the link text, or image. The typical example seen on many web pages is for changing the text in the status bar to a description of the target document, rather than a (generally) abstract URL. For example :

<A HREF="index.html" OnMouseOver="self.status=('Back to the main page')">Link text</A>

Would change the text in the status bar to 'Back to the main page'. Try it : Link text

NOTE : You may have to activate the status bar, by right clicking the title bar of this window. The return true keyword is required for this method to work properly in Netscape, although Internet Explorer is more relaxed and still changes the status bar text without it.

OnMouseOut
The opposite of OnMouseOver, OnMouseOut can be used to activate a script function when the users mouse leaves the area defined by the link text or image. (Currently this event handler is Netscape specific).

For (a silly) example, in Netscape, moving the mouse away from the following link would bring up the message 'Oh please go to this document' (I said it was silly).

<A HREF="index.html" OnMouseOut="alert('Oh please go to this document')">Link text</A>

OnClick
Unsurprisingly, this event handler can be used to execute a script function when the user clicks on the link text, or image. For example :

<A HREF="http://www.netscape.com/" OnClick="confirm('Are you sure you want to go to the Netscape site?')">Link text</A>

Give it a try : Link text

NOTE : If you actually wanted the above method to react to the users choice when presented with the confirmation dialog box, you'd need to take the confirm dialog out of the <A> element and call a script function. As the example is presented above, the browser would 'hit' the Netscape site regardless of the users choice. A full example (reacting to the confirmation) would need something like the following :

<A CLASS="external" HREF="#nowhere" OnClick="gotoNS()">Link text</A>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub gotoNS()
if confirm ("Are you sure you want to visit the Netscape site?") then
parent.location.href="http://www.netscape.com/"
else alert "I thought not"
end if
end sub
-->
</SCRIPT>

Give it a try : Link text

OnMouseMove
Internet Explorer supports using the OnMouseMove event handler for <A> links. It can be used to execute script functions when the user moves their mouse within the link area.
Generally, such code is useful when using images as links. It provides an alternative image map (see Client Side Image Maps), which can be used to give the user more feedback about their destination within the image map. For instance, the graphic can be displayed (using standard <IMG> HTML), surrounded by a <A> element, providing an ID for the link. For an example, see the OnMouseMove event section for the Link Object.


Attaching Scripts Scripting Reference Overview Scripting the <AREA> element