Marco Nashaat
Marco Nashaat

Reputation: 35

how to run two functions with a delay between them

so I have a click event and I'm planning to change the "src" of an image tag on clicking, wait a few seconds and then change it back.....

what I've tried:


function(){ //getting the img
                //changing the src attribute
                
                stTimeout(someCallbackFunction()
                     { //changing src attribut once again}
                           ,3000 //waiting 3 seconds)
}

//and ofcourse eventlistener

but it seems like the second function isnt getting used at all and i dont know what is the problem!!

Upvotes: 0

Views: 868

Answers (2)

MrCodingB
MrCodingB

Reputation: 2314

If you want to have two sepearte functions you can do it like @Lynx 242 did it. If you want to specify the callback immediately do it like this:

functionB(){ 
    /* code */

    setTimeout(() => {
        /* code */
    }, 3000); 
}

Upvotes: 1

user6749601
user6749601

Reputation:

It's supposed to look like this:

function funcA(){ /* code */ }

function funcB(){ 
    /* code */

    setTimeout(funcA, 3000); 
}
            

Upvotes: 1

Related Questions