How do I set textarea scroll bar to bottom as a default? How do I set textarea scroll bar to bottom as a default? javascript javascript

How do I set textarea scroll bar to bottom as a default?


pretty simple, in vanilla javascript:

var textarea = document.getElementById('textarea_id');textarea.scrollTop = textarea.scrollHeight;


You can use this with jQuery

$(document).ready(function(){    var $textarea = $('#textarea_id');    $textarea.scrollTop($textarea[0].scrollHeight);});


I had the same problem and found out that there is no attribute that can be set initially to get the right scrolling behaviour.However, once the text is updated in the textArea, immediately after in the same function you can set the focus() to textArea to make it scroll to bottom. You can then call focus() on some other input field as well to allow user to input in that field. This works like charm:

function myFunc() {    var txtArea = document.getElementById("myTextarea");    txtArea.value += "whatever"; // doesn't matter how it is updated    txtArea.focus();    var someOtherElem = document.getElementById("smallInputBox");    someOtherElem.focus();}