So I have a textarea in my html called code
. Here is my sample:
document.getElementById("code").addEventListener("input", function(ev) {
console.log(this.selectionStart),
console.log(this.selectionEnd),
console.log(ev.data)
})
<textarea id="code"></textarea>
When I've selected the whole text like this:
And I type a
- I get:
1
1
a
Instead of like:
1
9
a
I believe this is because it's first deleting the selected text and after that sending the input event on a blank textbox - any ideas how to get around this?
I'm trying to detect changes into the input so I can submit them to my server since I'm trying to implement live code sharing capability.