Reputation: 412
I have a link on page <a href="#"...
which linked with jquery function. After link was clicked the page scrolled to the top and this seems unnecessary behavior. Is there a way to prevent scrolling?
Upvotes: 0
Views: 74
Reputation: 24
you can use this : (prevent click)
<a href="javascript(0)" >...</a>
Upvotes: 0
Reputation: 11472
On click of your button you can prevent the default action using preventDefault():
$('a[href="#"]').on('click', function(event) {
event.preventDefault();
console.log('default action prevented');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href='#'>Button</a>
Upvotes: 0
Reputation: 167182
You can prevent following of #
by selecting them and using event.preventDefault()
:
$(function () {
$('a[href="#"]').click(function (e) {
e.preventDefault();
});
})
Upvotes: 1