how i can execute a jQuery function after a time period when event fire in jQuery?

delete my account picture delete my account · Apr 9, 2011 · Viewed 26.2k times · Source

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

Answer

Quentin picture Quentin · Apr 9, 2011
function myFunction () {
    // Code to do stuff after 300ms
}

$("#blah").keyup(function () {
               // Code to do stuff immediately
               setTimeout(myFunction, 300);
            });