Skip to content

Instantly share code, notes, and snippets.

@thomhines
Created April 16, 2017 19:11
Show Gist options
  • Save thomhines/908dc2e88bce84c5f06c9e9325b84f12 to your computer and use it in GitHub Desktop.
Save thomhines/908dc2e88bce84c5f06c9e9325b84f12 to your computer and use it in GitHub Desktop.
jQuery Debounce
var validation_debounce_timeout;
$.fn.debounce = function(callback, delay) {
$this = $(this);
clearTimeout(validation_debounce_timeout);
validation_debounce_timeout = setTimeout(function() {
callback();
}, delay);
}
// You must refer to "this" input as $this in callback function, like so:
$('input').debounce(function() {
console.log($this.val());
}, 700);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment