JSFiddle - React, Tailwind, and code Playground
HTML
<textarea id="test">Something</textarea>
JavaScript
function moveCaretToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
}
var textarea = document.getElementById("test");
textarea.onfocus = function() {
moveCaretToEnd(this);
// Work around Chrome's little problem
textarea.onmouseup = function() {
// Prevent further mouseup intervention
moveCaretToEnd(this);
textarea.onmouseup = null;
return false;
};
};