JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id="txt" rows="15" cols="70">There is some text here.</textarea>
<input type="button" id="btn" value="OK" />

JavaScript

jQuery("#btn").on('click', function() {
   var caretPos =document.getElementById("txt").selectionStart;
   var caretEnd = document.getElementById("txt").selectionEnd;
   var textAreaTxt = jQuery("#txt").val();
   var txtToAdd = "stuff";
   jQuery("#txt").val(textAreaTxt.substring(0, caretPos) + txtToAdd + textAreaTxt.substring( caretEnd ) );
});