files/en-us/web/api/htmlinputelement/select/index.md
{{ APIRef("HTML DOM") }}
The HTMLInputElement.select() method selects all the text
in a {{HTMLElement("textarea")}} element or in an {{HTMLElement("input")}} element
that includes a text field.
select()
None.
None ({{jsxref("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);
{{EmbedLiveSample("Examples")}}
Calling element.select() will not necessarily focus the input, so it is
often used with {{domxref("HTMLElement.focus")}}.
{{Specifications}}
{{Compat}}