About html link tag <a>'s HREF

1.adds # to the browser url and jumps to the top of the page.

<a href="#">link</a>
2.simply "ignores" the link click.

<a href="#" onclick="return false;">link</a>

<a href="#" onclick="foo(); return false;">link</a>

<a href="#" onclick="return foo();">link</a>

<a href="javascript:;">link</a>

<a href="javascript:void(0);">link</a>

<a href="javascript:return false;">link</a>


$('#myDiv a[href]').click(function (event) { 
      event.preventDefault();
      // your other click code here
});
The hash is safest, just in case your user has Javascript disabled.
You can solve it easily using jQuery to all the links with this value in your document :


$('a[href="#"]').click(function(e) {
    e.preventDefault ? e.preventDefault() : e.returnValue = false;
});

Comments

  1. What is different about event.preventDefault() and event.stopPropagation()?

    ReplyDelete

Post a Comment

Popular posts from this blog

Python3 + Django + uWSGI + Nginx On FreeBSD

arduino最小構成 (atmega328/8MHz/3.3V/内部クロック)FT232RLにてブートローダーの書き込み

FreeBSD: Configuring Apache to permit CGI