How can I get the cursor / caret position inside an HTML input element?

Should be pretty simple, but I can't find it on Google.

+1


a source to share


1 answer


You would use a property selectionStart

or selectionEnd

element input

.



setInterval(function(){
  console.log([document.getElementById("test").selectionStart, document.getElementById("test").

selectionEnd
------------

]);
}, 1000);
      

<input type="text" id="test"></input>
      

Run codeHide result


0


a source







All Articles