I had a similar problem, and linking to a dozen different events just doesn't shorten it, since there are so many different ways to change the input value, as bobince noted.
So - I ended up writing a dead simple jQuery monitoring plugin that is generic. With it, you can track changes in input values, changes in the text of a text field, changes in the contents of a div, etc.:
https://github.com/nixd3v/monitor
Track changes to div content:
$.monitor('add', function(){return $("div#someDiv").html()}, function(){ console.log('Div content changed'); });
Tracking input value changes:
$.monitor('add', function(){return $("#password").val()}, function(){ console.log('input value changed'); });
It also uses a loop, however, not through setInterval , but through the use of setTimeout along with a spontaneous anonymous function:
(function(){
What this means is that it ensures that the next call will not be made before your code is executed. If you use polling in your code, this is the right way to do it.
source share