Anchor tags list creation

In your javascript function you should return false, or with jquery you can use preventDefault()


$('a').click(function(event) {
    // do something

Or in your case:

<a href=“#” onclick="foo();return false;">

Or change the href to javascript:void(0):

<a href="" onclick="foo();">

Ideally, your link degrades without javascript, so the third option will usually be avoided.

A simpler HTML fix for you: Personally speaking, for plain test links I just use href=""

For links that point to a javascript function I tend to use href=";". Either way you’ll stop the page jumping.

Leave a Comment