Mestika
2/13/2015 - 10:48 AM

Delaying actions on keypress with jQuery

Delaying actions on keypress with jQuery

var delay = (function(){
  var timer = 0;
  return function(callback, ms){
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
  };
})();


$('input').keyup(function() {
    delay(function(){
      alert('Time elapsed!');
    }, 1000 );
});