How to scroll to the top of the page with jQuery?

I need to setup a user click action to scroll smoothly to the top of the page. Can someone please show a working code?


  • DavidMDavidM USA
    edited January 2014

    window.scrollTo(x-coord, y-coord);

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

    For smooth scrolling,

    $("a[href='#top']").click(function() {
          $("html, body").animate({ scrollTop: 0 }, "slow");
          return false;
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion