...">

JQuery input event doesn't work if input is empty

I have a jQuery event handler that responds to every change in

<input id="myId" type="text" /> 

element:

 $("#myId").bind('input', function (e) { // Do Stuff }); 

This works just fine unless the #myId input is empty (for example, there was only 1 character in the input field, and I delete it using Backspace). If the input is empty, the event does not fire. If I then enter a character, the event fires.

Is this a known issue? Am I doing something wrong? Any way to get an event when the input is empty?

Update

The event does not fire ALL EVERYTHING when Backspace is introduced, at least in IE9.

+5
source share
1 answer

as far as I know, enter is not the event you want to use. Since the β€œinput” is similar to the β€œchange”, it tends to produce poor results when your string approaches 0 characters, use keyup

 $("input#myId").bind('keyup', function (e) { // Do Stuff }); 
+8
source

All Articles