I tried using propertychange
as suggested by the top answer, but I noticed that sometimes it doesn't fire in IE8. For example after a page refresh with a prefilled input if I delete only one character.
My solution is to use keyup cut paste
events instead of propertychange
:
$('#myId').on('input keyup cut paste', function(e) {
setTimeout(function() {
doAwesomeThing();
}, 0);
});
I used setTimeout
with 0 delay because otherwise I would get the old input value on cut
and paste
events, see https://stackoverflow.com/a/9364812/2324685 for details.
You should note that this code might fire twice in some cases.