How can I get the character positions of the selected text in an HTML <input>
textbox element? window.getSelection()
doesn't work inside textboxes.
If you're using jQuery, take a look at the jQuery Caret plugin: jCaret
// Get start pos in intput box with id="box1"
$("#box1").caret().start
// Get end pos
$("#box1").caret().end
// Get selected text
$("#box1").caret().text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With