JSFiddle - React, Tailwind, and code Playground
HTML
Pass if there is nothing selected, and the caret is positioned after the second character(just before 'd' in 'different'.
<input type="text" value="0123456789" />
JavaScript
var txtb = document.getElementsByTagName('input')[0];
txtb.focus ();
txtb.value = "A different text";
txtb.selectionStart = txtb.selectionEnd = 2;