To scroll to the bottom of the page using JavaScript, you can set the scrollTop property of the document.documentElement or document.body elements to a large value, effectively scrolling to the end of the page. Here's how you can do it:

  1. Scroll to Bottom of the Page using Vanilla JavaScript: The following code will scroll the page to the bottom using plain JavaScript:

    javascript
    // Scroll to the bottom of the page function scrollToBottom() { document.documentElement.scrollTop = document.documentElement.scrollHeight; }

    Call the scrollToBottom function when you want to scroll to the bottom of the page.

  2. Scroll to Bottom of the Page using jQuery: If you are using jQuery, you can achieve the same effect like this:

    javascript
    // Scroll to the bottom of the page function scrollToBottom() { $('html, body').scrollTop($(document).height()); }

    Again, call the scrollToBottom function when you want to scroll to the bottom of the page.

  3. Smooth Scroll to Bottom of the Page: If you prefer a smooth scrolling effect, you can use the animate method in jQuery:

    javascript
    // Smooth scroll to the bottom of the page function scrollToBottom() { $('html, body').animate({ scrollTop: $(document).height() }, 'slow'); }

    The 'slow' parameter specifies the speed of the animation. You can adjust it to your preference or use a numeric value in milliseconds.

Remember to include the JavaScript code on your page, either in a script tag or in an external JavaScript file. After calling the scrollToBottom function, the page will scroll to the bottom, revealing the end of the content.

Have questions or queries?
Get in Touch