jQuery - on change input text

Marko Cakic picture Marko Cakic · May 3, 2012 · Viewed 128.2k times · Source

I am trying to make a function which will execute when the value of a text input field is changed. The value of the field changes when a table cell is clicked, not on keyup, nor paste. I tried it like this:

$("#kat").change(function(){ 
    alert("Hello");
});

And I have the text field:

<input type="text" id="kat" value="0"/>

but it isn't working. Any help?

Answer

aldux picture aldux · May 3, 2012

This is from a comment on the jQuery documentation page:

In older, pre-HTML5 browsers, "keyup" is definitely what you're looking for.

In HTML5 there is a new event, "input", which behaves exactly like you seem to think "change" should have behaved - in that it fires as soon as a key is pressed to enter information into a form.

$('element').bind('input',function);