JSFiddle - React, Tailwind, and code Playground

by Rachel Gallen

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>