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

  • Home
  • SEARCH
  • 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 6084915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:34:46+00:00 2026-05-23T11:34:46+00:00

Is there a way to delay the calling of a JavaScript function until two

  • 0

Is there a way to delay the calling of a JavaScript function until two criteria are met?

I have a slideUp() animation and a .get() function that start at the same time, but either one could finish first. I want a function to be called when both have completed.

  • 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-23T11:34:46+00:00Added an answer on May 23, 2026 at 11:34 am

    You just have to keep track, either a counter or (my preferred approach) flags for all relevant information.

    var slideDone, getDone;
    
    $("#foo").slideUp(function() {
        slideDone = true;
        nextThing();
    });
    $.get({
        // ...
        success: function() {
            getDone = true;
            nextThing();
        }
    });
    
    function nextThing() {
        if (slideDone && getDone) {
            // Do the next thing
        }
    }
    

    Now, obviously my two conditions above are very artificial, but I find that most of the time when this comes up in my real work, I have actual information I can use for the check and so don’t resort to artificial conditions.

    Or a counter:

    var counter = 0;
    
    ++counter;
    $("#foo").slideUp(function() {
        nextThing();
    });
    ++counter;
    $.get({
        // ...
        success: function() {
            nextThing();
        }
    });
    
    function nextThing() {
        if (--counter === 0) {
            // Do the next thing
        }
    }
    

    To someone used to multi-threaded programming, that looks like a race condition (what if the slideUp completes before we start the get?), but it’s not one in JavaScript on browsers, which is single-threaded (barring the use of web workers, which use a syntax that wouldn’t apply to the above anyway).

    If you find this coming up a lot, you could of course always isolate the logic (not that there’s a lot of it, but…) into an object and reuse it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to delay calling a superclass constructor so you can manipulate
Is there some way to delay defining the size of an array until a
Is there an easy way delay a method call for 1 second? I have
is there a way to delay the jump to an anchor tag on page
Is there way in next piece of code to only get the first record?
is there way how to get name ov event from Lambda expression like with
Is there a way to find the name of the program that is running
Is there a way in iOS4 to call a method after a delay using
Is there a way to tell JMS in JBoss to delay processing of messages
Is there any way to receive and identify DTMF signals when you get a

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.