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
123$(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:
SVN: How to commit only modified files via command line
How to add native menu support in your WordPress theme?
How to use apt to list available packages?
Turn on MySQL query cache to speed up query performance?
Symfony: PHP Fatal error: Call to a member function setData()
MySQL: Full text search for multiple words
Easy to use jQuery Lightbox - Fancybox
How to disable ssh root login?
Share this with your friends:-