JSFiddle - React, Tailwind, and code Playground
HTML
<head>
<script>
function f1(el) {
var val = el.value;
alert(val.slice(0, el.selectionStart).length);
}
</script>
</head>
<body>
<input type=text id="pos" placeholder="Enter text">
<button onmouseover="f1(document.getElementById('pos'))">Show position</button>
</body>