How to scroll automatically to the Bottom of the Page using jQuery?

To auto scroll a page from top to bottom we can use scrollTop() and height() method in jquery.
In this method pass the document’s height in scrollTop method to scroll.

Example-1: Scroll without animation.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>Scroll Automatically</title>
    <script src=
    </script>
  
    <!-- jQuery code to show the working of this method -->
    <script>
        $(document).ready(function() {
            $("button").click(function() {
                $(document).scrollTop($(document).height());
            });
        });
    </script>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <center>
        <div>
            <!-- click on this button
              and see the change -->
            <button>Click Here!</button>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
        </div>
    </center>
</body>
  
</html>

chevron_right


Output:

  • Before:
  • After:

Example-2: Scroll with animation.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>Scroll Automatically</title>
    <script src=
    </script>
  
    <!-- jQuery code to show 
      the working of this method -->
    <script>
        $(document).ready(function() {
            $("button").click(function() {
                $("html, body").animate({
                    scrollTop: $(
                      'html, body').get(0).scrollHeight
                }, 2000);
            });
        });
    </script>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <center>
        <div>
            <!-- click on this button
               and see the change -->
            <button>Click Here!</button>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
            <h1>GeeksforGeeks</h1>
        </div>
    </center>
</body>
  
</html>

chevron_right


Output:

  • Before:
  • After:


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.