Skip to content

Instantly share code, notes, and snippets.

@markwatson
Created February 23, 2015 19:27
Show Gist options
  • Save markwatson/1633176d2dd236efdb68 to your computer and use it in GitHub Desktop.
Save markwatson/1633176d2dd236efdb68 to your computer and use it in GitHub Desktop.
Helper to live check for input box changes in JavaScript.
$.fn.mwOnChange = function(callback, timeout) {
return $(this).each(function() {
if (timeout === undefined) {
timeout = 500;
}
var eventNames = 'keydown paste input';
var timeoutId = null;
$(this).on(eventNames, function(e) {
var self = this;
if (timeoutId !== null){
clearTimeout(timeoutId);
}
timeoutId = setTimeout(function() {
callback.apply(self, [e]);
}, timeout);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment