Search code examples
jqueryeventstextboxonkeyup

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


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


Solution

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