Example of Canceling the Default Behavior of a Link

This page has a link to the NYTimes website. Click the link.

Click to go to the NYTimes

As you see, clicking the link does not take you to the NYTimes website. This is because the <link> tag has an "onclick" attribute with some Javascript to run when a user clicks the link.

		<a href="http://nytimes.com" onclick="return doSomething();" >Click to go to the NYTimes</a>
That code tells the browser to call the function "doSomething" when a user clicks the link. The function says "return false;", which tells the browser not to follow through with the link when a user clicks it.