Is there a way of avoiding the jump when clicking on an anchor link? So that the view does not change.
The most semantic and meaningful approach to this problem would be to handle the onclick event from within JavaScript. Ideally this file would be best to be stored in a seperate file, however, including a in-line script within your problem file would suffice. Here's how i'd recommended approaching this problem if your already using a JavaScript library like jQuery.
Assign an ID
Include an id attribute to your anchor so it's able to be selected using jQuery:
<a href="#anchor" id="mylink" title="Title Here">Link Text</a>
Bind click event
From within your JavaScript file / in-line script include the following:
$('#mylink').click(function(event) {
// This will prevent the default action of the anchor
event.preventDefault();
// Failing the above, you could use this, however the above is recommended
return false;
});
The method above is explained in full using the jQuery API websites: http://api.jquery.com/event.preventDefault/
Just use:
<a href="javascript:void(0);">Text</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With