If u r building website with jQuery, it’s common if the browser auto scroll to top when user click on anchor element. This happen to me many times and i always forget how to disable the auto scrolling. Thus this post is being created for my own reference and for other developer 🙂
To disable autoscrolling to top when user click on anchor element, follow the steps below:
Advertisements
- In the same page, copy and paste this script within your script tag
$(document).ready(function() { $('body').on('click', '[href^=#]', function (e) { e.preventDefault() }); });
- Now refresh you page and you may try to click on anchor element and the autoscrolling should be stop by now
Happy coding!
Related posts:
Javascript: Prevent page from frameset hijack
WordPress: How to upload image using script?
Symfony Filter: Change ForeignKey drop down to Text field
How to sort drop down - Admin Generator - Symfony 1.4
Speed Up and Save Your Website Bandwidth with GZip Compression
Free image editor for Mac OS X / XP / Vista / Linux
MySQL: Full text search for multiple words
How to move Firefox tab bar to bottom
Share this with your friends:-