Skip to main content
2 of 2
Removed fluff. Rejects https://stackoverflow.com/review/suggested-edits/29982392 which didn't remove the fluff.
Wai Ha Lee
  • 8.9k
  • 102
  • 61
  • 100

Use this:

var textInput = document.querySelector("input"); textInput.onclick = function() { textInput.selectionStart = 0; textInput.selectionEnd = textInput.value.length; }
<input type="text">