How can I execute a jQuery function after a period of time when an event fires in jQuery?

I want to fire an event when a text field is activated 300 milliseconds later

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

when I try to execute this function, I find an error that myfunction is not a function.

so can someone explain how I can execute the 300 milisecond function later after pressing the keys in the text box

+7
source share
2 answers
 function myFunction () { // Code to do stuff after 300ms } $("#blah").keyup(function () { // Code to do stuff immediately setTimeout(myFunction, 300); }); 
+13
source

myfunction must be defined!

 $("#blah").keyup(function () { setTimeout(function(){ myfunction(); },300); }) 
+6
source

All Articles