Skip to content

Instantly share code, notes, and snippets.

@maneja81
Created May 26, 2017 12:17
Show Gist options
  • Save maneja81/6b37f634f184976471c2a95caf558303 to your computer and use it in GitHub Desktop.
Save maneja81/6b37f634f184976471c2a95caf558303 to your computer and use it in GitHub Desktop.
jQuery run function after user finished typing
let typingTimer; //timer identifier
let doneTypingInterval = 1500; //time in ms, 5 second for example
let $input = $('.search-sidebar-ui-blocks');
//on keyup, start the countdown
$input.on('keyup', function () {
clearTimeout(typingTimer);
typingTimer = setTimeout(doneTyping, doneTypingInterval);
});
//on keydown, clear the countdown
$input.on('keydown', function () {
clearTimeout(typingTimer);
});
//user is "finished typing," do something
function doneTyping() {
// do something here..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment