The HTMLInputElement.select() method selects all the text in a <textarea> element or in an <input> element that includes a text field.
select()None.
None (undefined).
Click the button in this example to select all the text in the <input> element.
<input type="text" id="text-box" size="20" value="Hello world!" />
<button>Select text</button>function selectText() {
const input = document.getElementById("text-box");
input.focus();
input.select();
}
document.querySelector("button").addEventListener("click", selectText);Calling element.select() will not necessarily focus the input, so it is often used with HTMLElement.focus.