Home >Web Front-end >JS Tutorial >How Can I Programmatically Scroll to the Bottom of a Web Page Using JavaScript?
Scroll to Bottom of Page Automatically
Looking to scroll to a specific element at the bottom of a page upon clicking a certain trigger? This can be achieved effectively without utilizing jQuery.
Solution:
window.scrollTo(0, document.body.scrollHeight);
Explanation:
This simple JavaScript code will scroll the page vertically to the position specified by the document.body.scrollHeight property. It represents the total height of the document's body, including any vertically scrolled elements.
Considerations:
In the case of nested elements, you may need to target the element that scrolls and use its scroll height instead:
nestedElement.scrollTo(0, nestedElement.scrollHeight);
Additional Resources:
The above is the detailed content of How Can I Programmatically Scroll to the Bottom of a Web Page Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!