How to set the default textarea scrollbar?

I have a text area that dynamically reloads as user input is entered. It is updated every couple of seconds. When the amount of text in this text box exceeds the size of the text box, a scroll bar appears. However, the scroll bar is not actually used, because if you start scrolling down, after a couple of seconds the text box will update and return the scroll bar up. I want the default scrollbar to display the bottommost text. Does anyone have an idea how to do this?

+59
javascript css scroll textarea
Feb 07 2018-12-12T00:
source share
2 answers

pretty simple in javascript vanilla:

var textarea = document.getElementById('textarea_id'); textarea.scrollTop = textarea.scrollHeight; 
+121
Feb 07 2018-12-12T00:
source share

You can use this with jQuery

 $(document).ready(function(){ var $textarea = $('#textarea_id'); $textarea.scrollTop($textarea[0].scrollHeight); }); 
+37
Feb 07 2018-12-12T00:
source share



All Articles