Bind to keydown and compare the value from before and after to see if it has decreased.
$(input).keydown(function(){ var currVal = this.value, self = this; setTimeout(function(){ if ( currVal.length > self.value.length ) { console.log(currVal.length - self.value.length + " characters have been removed."); } },0); });
http://jsfiddle.net/ymhjA/1/
Updated example:
$("input").keydown(function() { var currVal = this.value, self = this; setTimeout(function() { if (currVal.length - self.value.length === 1) { var origVal = $.grep(currVal.split(""),function(val){ return val === " "; }); var newVal = $.grep(self.value.split(""),function(val){ return val === " "; }); if ( origVal.length != newVal.length ) { console.log("a space was removed"); } } }, 0); });β
http://jsfiddle.net/ymhjA/4/
source share