How can I call some javascript functions but, waiting for the previous has finished?

Posted by texai on Stack Overflow See other posts from Stack Overflow or by texai
Published on 2011-03-04T15:18:59Z Indexed on 2011/03/04 15:24 UTC
Read the original article Hit count: 259

I want to call some functions but waiting for the previous one has finished. I know jQuery provides a callback argument in several functions, but I want to learn how implement this behaviour in my own jQuery plugin. So this is the case:

After read answers from my previous question I wrote this:

    (function(callback){
        $('#art1').animate({'width':'1000px'},1000);
        callback();
    })((function(callback2){
        $('#art2').animate({'width':'1000px'},1000);
        callback2();
    })(function(){
        $('#art3').animate({'width':'1000px'},1000);
    }));

But still not working. Three animates still starting at same time. I want they were called one after other. But without using:

    $('#art1').animate({'width':'1000px'},1000,'linear',function(){
        $('#art2').animate({'width':'1000px'},1000,'linear',function(){
            $('#art3').animate({'width':'1000px'},1000);        
        });        
    });  

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery