By making a small tweak to the getCursorPosition function in this thread , you can get characters deleted by tracking the current cursor selection.
The code processes the following conditions:
- Type and then back to the end.
- Move the cursor in the middle of the text and delete / return.
- Select a piece of text and then delete / backspace.
$.fn.getCursorPosition = function() { var el = $(this).get(0); var pos = 0; var posEnd = 0; if('selectionStart' in el) { pos = el.selectionStart; posEnd = el.selectionEnd; } else if('selection' in document) { el.focus(); var Sel = document.selection.createRange(); var SelLength = document.selection.createRange().text.length; Sel.moveStart('character', -el.value.length); pos = Sel.text.length - SelLength; posEnd = Sel.text.length; }
And here is the Live Demo
source share