delaying actions between keypress in jQuery
You can use jQuery’s data abilities to do this, something like this: $(‘#mySearch’).keyup(function() { clearTimeout($.data(this, ‘timer’)); var wait = setTimeout(search, 500); $(this).data(‘timer’, wait); }); function search() { $.post(“stuff.php”, {nStr: “” + $(‘#mySearch’).val() + “”}, function(data){ if(data.length > 0) { $(‘#suggestions’).show(); $(‘#autoSuggestionsList’).html(data); }else{ $(‘#suggestions’).hide(); } }); } The main advantage here is no global variables all … Read more