Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created October 5, 2016 19:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/85c2d634c6c0fb82224ff43de2d791e8 to your computer and use it in GitHub Desktop.
Save james2doyle/85c2d634c6c0fb82224ff43de2d791e8 to your computer and use it in GitHub Desktop.
A debounce timeout trigger for typing in an input. The example is in jQuery, but this works with any event/listener.
$('#input').on('keyup', function() {
// do an ajax save when this input is changed
var val = this.value;
// clear the timeout so we dont fire in succession
clearTimeout(this.delayer);
this.delayer = setTimeout(function () {
console.log(val);
}, 500);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment