Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6574675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:17:25+00:00 2026-05-25T15:17:25+00:00

I don’t know if calling this nesting is correct or not? But I know

  • 0

I don’t know if calling this nesting is correct or not? But I know it’s not a good code to have many function inside each others. Most of the jQuery methods have callback function that we can put our callbacks in there. But when we do callbacks inside another callback and continue this and going deeper and deeper it seems code become less readable and maybe less debuggable.

For example if I want to do some animations after each other I have to call every animation that I want to come after another one in it’s callback function. It will go deeper and deeper in callback function. Look at this example(fiddle):

$('#t').animate({height: 400}, 500, function(){
    $(this).animate({height: 200}, 500, function(){
        $(this).animate({width: 300}, 500, function(){
            $(this).animate({height: 300}, 500, function(){
                $(this).animate({'border-radius': '50px'}, 500, function(){
                    //and so on...
                });
            });
        });
    });
});

for doing a 5 steps animation I have to make a 5 level call stack. So my question is how you avoid this? I had same problem in my Node.js functions too.

Update:
I know jQuery function have chinning feature but that don’t solve the problem. because you can’t do something in between of the chain. You could write above code like $(selector').animate().animate()... but you can’t do same for this:

$('#t').animate({height: 400}, 500, function(){
        console.log('step 1 done: like a boss');
        $(this).animate({height: 200}, 500, function(){
            console.log('step 2 done: like a boss');
            $(this).animate({width: 300}, 500, function(){
                console.log('step 3 done: like a boss');
                $(this).animate({height: 300}, 500, function(){
                    console.log('step 4 done: like a boss');
                    $(this).animate({'border-radius': '50px'}, 500, function(){
                        //and so on...
                    });
                });
            });
        });
    });

The ideal solution would be a code like this:

$(selector).doQ(anim1, anim2, myfunc1, anim3, myfunc2)...

But sadly jQuery don’t have an API like this(to my knowledge).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:17:26+00:00Added an answer on May 25, 2026 at 3:17 pm

    *"The ideal solution would be a code like this:

    $(selector).doQ(anim1, anim2, myfunc1, anim3, myfunc2)…"*

    This isn’t quite what you want, but jQuery does have the queue()[docs] method:

    $(selector).animate({height: 400}, 500)
               .animate({height: 200}, 500)
               .queue( myfunc1 )
               .animate({width: 300}, 500)
               .queue( myfunc2 );
    

    You just need to make sure that your functions release the queue when they’re done by using the dequeue()[docs] method:

    function myfunc1() {
        // your code
        $(this).dequeue();
    }
    

    Or you can wrap your functions in an anonymous function, and invoke then dequeue there:

    $(selector).animate({height: 400}, 500)
               .animate({height: 200}, 500)
               .queue( function( nxt ) {
                   myfunc1();
                   $(this).dequeue();
                })
               .animate({width: 300}, 500)
               .queue( function( nxt ) {
                   myfunc2();
                   nxt(); // alternate way to dequeue
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know why but I can't find a solution to this. I have 3
I don't know if this question is trivial or not. But after a couple
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this is the right place to ask this, but I will
Don't know if this is an eclipse specific problem but whenever I declare a
I don't know why this double json response are not successful: [{first_content:content,...}][{second_content:content,...}] So i
Don't know if this has been answered before. Have custom routes to users. If
I don't know if this has been asked before, but what i'd like to
I don't know: if this works. if it's a good idea. what it is
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.