Search code examples
javascriptjqueryscrollscrolltojs-scrollintoview

Scroll Automatically to the Bottom of the Page


I have a list of questions. When I click on the first question, it should automatically take me to a specific element at the bottom of the page.

How can I do this with jQuery?


Solution

  • jQuery isn't necessary. Most of the top results I got from a Google search gave me this answer:

    window.scrollTo(0, document.body.scrollHeight);
    

    Where you have nested elements, the document might not scroll. In this case, you need to target the element that scrolls and use its scroll height instead.

    nestedElement.scrollTo(0, nestedElement.scrollHeight);
    

    Some additional sources you can take a look at: