how to select input element javascript

Solutions on MaxInterview for how to select input element javascript by the best coders in the world

showing results for - "how to select input element javascript"
Nico
14 Feb 2019
1<input type="text" id="text-box" size="20" value="Hello world!">
2<button onclick="selectText()">Select text</button>
3
4<script>
5  /* Use The
6  .focus();
7  .select(); 
8  Methods */
9function selectText() {
10  const input = document.getElementById('text-box');
11  input.focus();
12  input.select();
13}
14</script>