Get cursor postion in characters in textarea - Javascript

How can I get the current cursor position in textbox / textarea by using Javascript function ?
posted on 19.12.2019 at 19:14
0pnshow more

To get the current cursor position in Javascript, you can use this solution:


function cursorPosition() {
var content = document.getElementById('text');
var position = content.selectionStart;
else {
return false;


<textarea id='text' style='width: 300px; height: 150px;' ></textarea>
<br />
<a href='javascript:void(0);' onClick='javascript: cursorPosition();' >Get cursor position</a>
<br />
<div id='pos'></div>

The function may not be supported in all browsers, but it works in the "relevant ones".

posted on 22.12.2019 at 15:23
0pnshow more
share on facebookshare on twitter
2021 AnswerTabsTermsContact us