JSFiddle - React, Tailwind, and code Playground

by rajesh38

HTML

<html>
    <head>
    <script>
        function f1(el) {
        var val = el.value;
        alert(val.slice(0, el.selectionStart).length);
    }
    </script>
    </head>
    <body>
    <input type=text id=t1 value=abcd>
        <button onclick="f1(document.getElementById('t1'))">check position</button>
    </body>
    </html>