How to Scroll to the top of the page using JavaScript/ jQuery?


Example

Live Demo

<html>
   <body>
      <script>
         $("a").click(function() {
            $("html, body").animate({ scrollTop: 0 }, "slow");
            return false;
         });
      </script>
      <h3>TOP OF PAGE</h3>
      <br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.<br>
      This is demo text.
      <br>
      <h3>BOTTOM OF PAGE</h3>
      <a href="#">Scroll up</a>
   </body>
</html>

Updated on: 16-Jun-2020

140 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements