JSFiddle - React, Tailwind, and code Playground
HTML
Address:<br>
<textarea id="myTextarea">
California Road
</textarea>
<p>Click the button to select the contents of the text area.</p>
<button id="button">Try it</button>
JavaScript
function go() {
var e = document.getElementById("myTextarea");
var startPos = e.selectionStart;
var endPos = e.selectionEnd;
var selection = e.value.substring(startPos, endPos) ;
alert("It seems to have disappeared, but...\n\"" + selection + "\"");
e.focus();
}
var btn = document.getElementById("button");
btn.addEventListener(
"click",
go,
false
);