JSFiddle - React, Tailwind, and code Playground
HTML
<script>
function getCursorPos(el) {
var val = el.value;
document.getElementById("CursorPos").innerHTML=val.slice(0, el.selectionStart).length;
}
</script>
<input type=text id="t1" value="abcd" onclick="getCursorPos(this);">
<div id="CursorPos"></div>