Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
stop scrolling to top after AJAX request

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

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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>
over 4 years ago · Santiago Trujillo Report

0

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/") })
over 4 years ago · Santiago Trujillo Report

0

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>.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!