Categories
JavaScript Answers

How to set textarea scroll bar to bottom as a default with JavaScript?

Spread the love

Sometimes, we want to set textarea scroll bar to bottom as a default with JavaScript.

In this article, we’ll look at how to set textarea scroll bar to bottom as a default with JavaScript.

How to set textarea scroll bar to bottom as a default with JavaScript?

To set textarea scroll bar to bottom as a default with JavaScript, we set the textarea scrollTop property to the value of the textarea scrollHeight property.

For instance, we write

const textarea = document.getElementById("textarea_id");
textarea.scrollTop = textarea.scrollHeight;

to select the textarea element with getElementById.

Then we set the textarea.scrollTop property to the textarea.scrollHeight value to scroll the textarea to the bottom of it.

Conclusion

To set textarea scroll bar to bottom as a default with JavaScript, we set the textarea scrollTop property to the value of the textarea scrollHeight property.

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 *