Scriptbaker
SCRIPTBAKERAI & Software Engineering
JavaScript

keyup function with delay

This code will execute a function after the user has stopped typing for a time of 1000ms. Hence the function will not be called on each keyup event. Grea

· 5 min read

This code will execute a function after the user has stopped typing for a time of 1000ms. Hence the function will not be called on each keyup event. Great!!!

 jQuery(function(){ 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 ); }); }); 

S

Scriptbaker Editorial Team

The Scriptbaker editorial team comprises engineers, AI specialists, and digital strategists based in Dubai and Rawalpindi. We write about software development, artificial intelligence, and digital transformation to help organisations build better products. Learn more about us →