Edit in JSFiddle

const input = document.querySelector('input[type="text"]');
const logger = document.querySelector('#log');

function log() {
  logger.innerText = `
  selectionStart: ${input.selectionStart},
  selectionEnd:${input.selectionEnd}
  `;
}

input.addEventListener( 'focus', log, false );
input.addEventListener( 'keyup', log, false );
<input type="text" placeholder="Type anything" style="font-size:14px">
<pre id="log"></pre>