JSFiddle - React, Tailwind, and code Playground
HTML
<div id="test" contenteditable="true" placeholder="">
Focus and place the cursor to the end
</div>
JavaScript
$(document).ready(function(){
focusAndPlaceCaretAtEnd($('#test'));
});
function focusAndPlaceCaretAtEnd(el) {
el.focus();
if (typeof window.getSelection != "undefined"
&& typeof document.createRange != "undefined") {
var range = document.createRange();
range.selectNodeContents(el);
range.collapse(false);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
} else if (typeof document.body.createTextRange != "undefined") {
var textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.collapse(false);
textRange.select();
}
}