Android Selection State

by Atty Eleti

HTML

<input id="test" type="email">

JavaScript

const input = document.getElementById("test");

input.addEventListener('keyup', (e) => {
  const value = e.target.value;
  const selectionStart = input.selectionStart;
  const selectionEnd = input.selectionEnd;
  console.log(`keyup: value: ${value}, [${selectionStart}, ${selectionEnd}]`);
})

input.addEventListener('input', (e) => {
  const value = e.target.value;
  const selectionStart = input.selectionStart;
  const selectionEnd = input.selectionEnd;
  console.log(`input: value: ${value}, [${selectionStart}, ${selectionEnd}]`);
})

input.addEventListener('change', (e) => {
  const value = e.target.value;
  const selectionStart = input.selectionStart;
  const selectionEnd = input.selectionEnd;
  console.log(`change: value: ${value}, [${selectionStart}, ${selectionEnd}]`);
})