Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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