Demo of selecting text
3 years ago in HTML
<!DOCTYPE html>
<html>
<body>
Name: <input type="text" id="myText" value="Mickey">
<p>Click the button to select the contents of the text field.</p>
<button type="button" onclick="myFunction()">Try it</button>
<script>
function myFunction() {
const el = document.getElementById("myText");
el.focus();
el.select();
}
</script>
</body>
</html>