You need to call event.preventDefault(); somewhere in the click event handler. In vanilla javascript, this can be done like this:
<script type="text/javascript"> function foo(e) { e.preventDefault(); </script> <a href="#" onclick="foo(e);"></a>
Alternatively, you can also return false:
<a href="#" onclick="foo();return false;/>
This can also be done in jQuery quite simply:
$('.mylink').click(function(e) { e.preventDefault();
The downside of using return false; is that it also prevents the event from flowing into the DOM. If you don't care about event bubbles, it's ok to use a lie, but personally, I feel it is better to use event.preventDefault(); unless you specifically want to stop the event bubbles.
source share