[ACCEPTED]-stop scrolling to top after AJAX request-scroll

Accepted answer
Score: 37

you should add return false to the end of your ajax 2 call function. Or to the end of your inline 1 call:

<a href="#" onclick="someAjaxCall(); return false">Link</a>
Score: 9

if you are calling the ajax via anchor click, try 1 this:

<a id="clicker" href="#">Click here to do ajax</a>

$('#clicker').click(function(e) { e.preventDefault(); $.get("/myurl/") })
Score: 5

Attach the event handler with jQuery (not 8 with the onclick attribute) and remove the 7 href attribute altogether. The problem is 6 that the browser is navigating when the 5 link is clicked. I see this happen alot 4 when onclick is used and there is an error 3 in your event handler before preventing 2 the default.

Another way to fix it for sure 1 is to not use an <a> but rather a <span>.

Score: 2
/* AJAX stuff here */
$('html, body').stop();


More Related questions