JSFiddle - React, Tailwind, and code Playground
HTML
<input id="test" size="50" value="Some lovely text, please select it">
<input type="button" value="Click me to move the focus">
<div id="info"></div>
JavaScript
window.setInterval(function() {
var input = document.getElementById("test");
document.getElementById("info").innerHTML = "Selection start: " + input.selectionStart + ", end: " + input.selectionEnd + ". Is active element: " + (input == document.activeElement);
}, 200);