Search code examples
javascriptjquerydelay

jquery delay between javascript functions


I have multiply functions with parameters simplified as:

    function f1(p1,p2){
        alert('Function one is P1:'+p1+' P2:'+p2);        
    }
    function f2(p1,p2){
        alert('Function two is P1:'+p1+' P2:'+p2);
    }

I need to fire these is a sequence with a delay between. I have however found that jQuery dislikes running functions with parameters. I have tried the .click function.

$.delay(1000).click(f1('One',false)).delay(1000).click(f2('One',false));

But the delay makes the click functions not work...


Solution

  • I would just use a simple timeout:

    f1("one", false);
    setTimeout(function() { f2("one", false); }, 1000);