Categories
JavaScript Answers

How to scroll to bottom of div with JavaScript?

Spread the love

To scroll to bottom of div with JavaScript, we set scrollTop to scrollHeight.

For instance, we write

const objDiv = document.getElementById("your_div");
objDiv.scrollTop = objDiv.scrollHeight;

to get the div with getElementById.

Then we set its scrollTop property to its scrollHeight value to scroll to the bottom.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *