jQuery 'input' event

silkfire picture silkfire · Jun 29, 2013 · Viewed 257.9k times · Source

I've never heard of an event in jQuery called input till I saw this jsfiddle.

Do you know why it's working? Is it an alias for keyup or something?

$(document).on('input', 'input:text', function() {});

Answer

J David Smith picture J David Smith · Jun 29, 2013

Occurs when the text content of an element is changed through the user interface.

It's not quite an alias for keyup because keyup will fire even if the key does nothing (for example: pressing and then releasing the Control key will trigger a keyup event).

A good way to think about it is like this: it's an event that triggers whenever the input changes. This includes -- but is not limited to -- pressing keys which modify the input (so, for example, Ctrl by itself will not trigger the event, but Ctrl-V to paste some text will), selecting an auto-completion option, Linux-style middle-click paste, drag-and-drop, and lots of other things.

See this page and the comments on this answer for more details.