My question is similar to this, but none of the answers solve my problem: Use jQuery preventDefault (), but add the path to the URL
When the user clicks the link to the fragment, I need to remove the default behavior to go to the fragment, but at the same time add the fragment to the URL. This code (taken from the link) will trigger the animation and then add the snippet to the URL. However, after this, the fragment moves, which in my case breaks my site.
$("#login_link").click(function (e) { e.preventDefault(); $("#login").animate({ 'margin-top': 0 }, 600, 'linear', function(){ window.location.hash = $(this).attr('href'); }); });
Evans source share