// select() in javascript
// add below code to your javascript file
function selectText() {
const input = document.getElementById('text-box');
input.focus();
input.select();
}
// add below code to your html file
<input type="text" id="text-box" size="20" value="Hello world!">
<button onclick="selectText()">Select text</button>
function selectText() {
const input = document.getElementById('text-box');
input.select();
}
javascript DOM Selection