Please do not pass the setTimeout string, in this case there is no need, you can call the function directly as follows:
$(function() { $('#searchbox').keyup(function() { if($(this).data("timeout")) clearTimeout($(this).data("timeout")); $(this).data("timeout", setTimeout(input, 2000)); }); });
As with the queue queuing problem, you just need to clear the previous timeout (2 to 2 seconds ago), as before. In addition, you can save this timeout locally in the element using .data() , as it was above, fewer global variables, and you can use this in many elements instead of the timeout variable for each.
source share