You can use properties selectionStart
and selectionEnd
to get the indices of the corresponding values.
var start = document.getElementById("myArea").selectionStart;
var end = document.getElementById("myArea").selectionEnd;
console.log(start);
console.log(end);
source
to share