9

I want to fire a event on keyup of textbox 300 milisecond later

$("#blah").keyup(function () {
               //code is here
            }).delay(300).myfunction();

when i try to execute this function i found error that myfunction is not a function.

so can anyone explain how i can execute a function 300 milisecond later after keyup in a textbox

3 Answers3

14
function myFunction () {
    // Code to do stuff after 300ms
}

$("#blah").keyup(function () {
               // Code to do stuff immediately
               setTimeout(myFunction, 300);
            });
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
8

myfunction must be defined!

$("#blah").keyup(function () {

setTimeout(function(){
            myfunction();
         },300);
})
Headshota
  • 21,021
  • 11
  • 61
  • 82
0

As docs say, from version 1.4 on-wards, you can use delay() function

$( "#foo" ).slideUp( 300 ).delay( 800 ).fadeIn( 400 );
AmiNadimi
  • 5,129
  • 3
  • 39
  • 55