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

3

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

Anjelicaanjou answered 9/4, 2011 at 6:29 Comment(0)
W
14
function myFunction () {
    // Code to do stuff after 300ms
}

$("#blah").keyup(function () {
               // Code to do stuff immediately
               setTimeout(myFunction, 300);
            });
Waterfowl answered 9/4, 2011 at 6:31 Comment(0)
S
8

myfunction must be defined!

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

setTimeout(function(){
            myfunction();
         },300);
})
Spiritual answered 9/4, 2011 at 6:32 Comment(0)
M
0

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

$( "#foo" ).slideUp( 300 ).delay( 800 ).fadeIn( 400 );
Mccall answered 12/5, 2018 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.