Skip to content

Instantly share code, notes, and snippets.

@drakakisgeo
Created May 17, 2014 15:43
Show Gist options
  • Save drakakisgeo/5f1e3eac8d0fc6dedfb0 to your computer and use it in GitHub Desktop.
Save drakakisgeo/5f1e3eac8d0fc6dedfb0 to your computer and use it in GitHub Desktop.
Delay keyup in Jquery
*** executing a function after the user has stopped typing for a specified amount of time ***
*** From http://stackoverflow.com/questions/1909441/jquery-keyup-delay ***
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
Usage:
$('input').keyup(function() {
delay(function(){
alert('Time elapsed!');
}, 1000 );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment