How to jump to top of browser page

Exitos picture Exitos · Nov 10, 2010 · Viewed 269.4k times · Source

I'm writing a modal popup and I need the browser to jump to the top of the screen when the open modal button is pressed. Is there a way to scroll the browser to the top using jQuery?

Answer

Nick Craver picture Nick Craver · Nov 10, 2010

You can set the scrollTop, like this:

$('html,body').scrollTop(0);

Or if you want a little animation instead of a snap to the top:

$('html, body').animate({ scrollTop: 0 }, 'fast');