How to scroll to the top of the page with JQuery

Waqas Anwar
26 August 2014

There are many ways to achieve this functionality as shown in following code snippet.

You can use scrollTo function of window object like this:
window.scrollTo(x-coord, y-coord);

x-coord is the pixel along the horizontal axis.
y-coord is the pixel along the vertical axis.

If you want smooth scrolling, try something like this:
 $("html, body").animate({ scrollTop: 0 }, "slow");