text caret position
HTML
<input id="txt" value="some text here" />
<input type="button" id="btn" value="OK" />
CSS
#txt {
width: 300px;
}
JavaScript
jQuery("#btn").on('click', function() {
var caretPos = document.getElementById("txt").selectionStart;
var textAreaTxt = jQuery("#txt").val();
var txtToAdd = "more text";
console.log(caretPos)
jQuery("#txt").val(textAreaTxt.substring(0, caretPos) + txtToAdd + textAreaTxt.substring(caretPos) );
});