You can use the preventDefault() function to do what you want.
Here is an example using <textarea> , but it should extend to any element:
http://jsfiddle.net/4dThe/
$('#txtArea').keydown(function(e) { if (e.which == 8) { var value = $(this).val(); var lastchar = value.substring(value.length - 1); alert("Last character is: " + lastchar); $(this).val(value.substring(0, value.length - 1)); e.preventDefault(); } });
The preventDefault() method blocks the backspace operation, so the last character is not deleted. Then you can see what the last character is and do the backspace operation yourself.
You will need to modify the above example to determine the current cursor position in order to delete the correct character, but this is the beginning.
Nibblypig
source share