This question already has answers here:
Closed 7 years ago.
Possible Duplicate:
How do I stop a web page from scrolling to the top when a link is clicked that triggers javascript?
my browser scrolls to top after ajax request then i use
$('html, body').animate({ scrollTop: $('#loadMore').offset().top }, 2000);
to scroll back to my div.
is there a way i stop it from scrolling to top from the beginning
you should add return false
to the end of your ajax call function. Or to the end of your inline call:
<a href="#" onclick="someAjaxCall(); return false">Link</a>
if you are calling the ajax via anchor click, try this:
<a id="clicker" href="#">Click here to do ajax</a>
$('#clicker').click(function(e) { e.preventDefault(); $.get("/myurl/") })
Attach the event handler with jQuery (not with the onclick attribute) and remove the href attribute altogether. The problem is that the browser is navigating when the link is clicked. I see this happen alot when onclick is used and there is an error in your event handler before preventing the default.
Another way to fix it for sure is to not use an <a> but rather a <span>.
/* AJAX stuff here */
$('html, body').stop();