Skip to content

Instantly share code, notes, and snippets.

@netsuite
Last active December 16, 2015 08:09
Show Gist options
  • Save netsuite/5404293 to your computer and use it in GitHub Desktop.
Save netsuite/5404293 to your computer and use it in GitHub Desktop.
js: observe input event
//Observe input events
// Do your stuff after 1 seconds of last user input
$(document).on('input keyup', '.observe', function () {
var $this = $(this);
var delay = 500; // 0.5 seconds delay after last input
clearTimeout($this.data('timer'));
$this.data('timer', setTimeout(function () {
$this.removeData('timer');
// Do your stuff after 0.5 seconds of last user input
if ($this.val()) {
$this.trigger('change');
}
}, delay));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment