Pages

Monday, March 03, 2008

Cancelling clicked href link in html

If we want to create a link which is not linked to anywhere but only want to trigger something example as follows:
<a href="#" onclick="alert('test');">...</a>

The page will scroll to the top since the link is nowhere found in that page. To disable the scroll, simply add return false like this:
<a href="#" onclick="alert('test'); return false;">...</a>

or
<a href="" onclick="alert('test'); return false;">...</a>

That's all. :)

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete