I want to get the current cursor position when a user clicks inside a filled input box. But using this.selectionStart; only gives '0' using the following code:
$('.exampleDiv').on('focus', 'input', function() {
console.log(this.selectionStart);
});
Html
<div class="exampleDiv" style="width=300px;"><input value="This is a prefilled value"></div>
My guess is that it gives the value 0 because the .on(focus) code runs before the cursor position is set in the input box.
Is there any other event for input element activation which can be used?
Example: Input box has value: "This is a prefilled value"
User clicks on "pre|filled" so I want to get the number of characters after which the cursor appears. Is there a way to get this?