I know there are smiliar questions but I didn't get my answer.
function setTextareaSelection(newText) {
var selText;
newText = "This is a text \n to insert";
var textarea = document.getElementById('textarea');
if (window.getSelection) {
var selText = "";
selText = textarea.value.slice(textarea.selectionStart, textarea.selectionEnd);
var selEnd = textarea.selectionEnd;
var selTextBefore = textarea.value.substring(0, textarea.selectionStart);
var selTextAfter = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
if (selText != "") {
textarea.value = selTextBefore + newText + selTextAfter;
textarea.setSelectionRange(selEnd, selEnd);
}
}
}
I want to place mouse cursor after the inserted text.
Firefox only
Online example: link text