-1

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...

6
  • Agreed - no need for jQuery at all here. Not sure what the click connection is. Commented Aug 2, 2012 at 16:43
  • jQuery's queue method is relevant for performing actions on DOM nodes between animations and the like. Commented Aug 2, 2012 at 16:45
  • $.delay is not a valid method unless you're using a plugin that you haven't told us about. Commented Aug 2, 2012 at 16:45
  • I just don't understand how .click was a possible solution to this problem. Commented Aug 2, 2012 at 16:52
  • thanks for all the answers, my problem is however that I have 7 functions all needing to be executed with a delay, some of them a jquery some a normal and some are both... Commented Aug 2, 2012 at 18:15

4 Answers 4

9

I would just use a simple timeout:

f1("one", false);
setTimeout(function() { f2("one", false); }, 1000);
Sign up to request clarification or add additional context in comments.

Comments

0
$.delay(1000).click(function(){f1('One',false);}).delay(1000).click(function(){f2('One',false);});

not sure what the click is for though ...

Comments

0

if you want to delay a function call then a much simpler way is to use setTimeout().

eg: // calling it in a nested setTimeout for sequential delayed execution setTimeout(function(){

 f1('One',false);
  setTimeout(function(){
    f1('One',false)
  },300)
},300)

Comments

0
function fn1()
{
    alert(1);
}
function fn2()
{
    alert(2);
}
var arr=[fn1,fn2];
var len=arr.length;
var time=1000;
for(var k=0;k<len;k++)
{
    (function(k)
    {
        setTimeout(arr[k],time);
    }(k))
    time=time*2;
}

It executes after a delay of 1 second! DEMO

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.