Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Web
Expertise: Beginner
Feb 25, 1999

Calling JavaScript in an Anchor Tag

There are many ways to call a JavaScript function in an HTML document. One way is inside an anchor tag. Any function that is listed in the <HEAD> portion of the document can be called within an anchor, and the anchor tag can refer to either text or an image.
<SCRIPT language="JavaScript">
function anchor_test() {
	window.alert("This is an anchor test.")
<A HREF="javascript:anchor_test()">Test</a>

This technique doesn't rely on any event handlers such as onMouseover or onClick, which may behave differently in different browsers and browser versions.
Steve Renaker
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.