Failed to execute ‘setSelectionRange’ on ‘HTMLInputElement’: The input element’s type (‘number’) does not support selection

I know this is an old question, but I did find a good workaround without using the tel input type. By changing the input type from number to text before the selection, the error goes away and you get to keep all the benefits of the number input type.

  • tel allows text input, which may not work with numbers.
  • tel does not show the number “spinner” next to the input (only if you want it).
function onInputFocus(event) {
  const target = event.currentTarget;

  target.type="text";
  target.setSelectionRange(0, target.value.length);
  target.type="number";
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)