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 6917683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:45:40+00:00 2026-05-27T09:45:40+00:00

I have a function that needs to call some functions sequentially. First, a fadeOut

  • 0

I have a function that needs to call some functions sequentially. First, a fadeOut is called on a DOM node. In a callback, the DOM node is detached. This is function #1. But, after that is done, I need to call function #2.

So:

var func1 = function() {
    console.log('func 1 start');
    elt.fadeOut(2000, callback);
    console.log('func 1 end');
};
var func2 = function() {
    console.log('func 2 start');
    console.log('func 2 end');
};
var callback = function() {
    console.log('func 1 callback start');
    elt.detach();
    console.log('func 1 callback end');
};
func1();
func2();

The above outputs:

func 1 start
func 1 end
func 2 start
func 2 end
func 1 callback start
func 1 callback end

I need the callback to finish before func2() is called. How do I do it?

Working example here: http://jsfiddle.net/y2vj8/2/

[EDIT]:

OK, it seems necessary to give you some explanation of why I want func2() called after the callback is finished, else I don’t foresee getting an answer soon :(.

func1 fades a div (call it div1) out and then detaches is from the DOM. This is a publicly available function.

func2 is a user-defined callback to a certain event (a click on some other div, say, div2). It may be undefined, but it may contain absolutely any code.

When div2 is clicked, func1() is called, then func2() is evaluated, and if it is a function, it is also called.

If the user calls func1() manually, func2() is never called.

func1 is unaware of the click event on div2 and therefore cannot check whether func2 should be called or not.

  • 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-27T09:45:41+00:00Added an answer on May 27, 2026 at 9:45 am

    You could do something really silly like this (jsFiddle):

    var func1 = function(callback) {
        console.log('func 1 start');
        $('#fadeOut').fadeOut(2000, function() { func1_callback(callback) });
        console.log('func 1 end');
    
    };
    var func2 = function() {
        console.log('func 2 start');
        console.log('func 2 end');
    };
    var func1_callback = function(callback) {
        console.log('func 1 callback start');
        $('#fadeOut').detach();
        console.log('func 1 callback end');
        callback.call();
    };
    func1(func2);
    

    Honestly, I’d probably look at restructuring your app. I don’t understand why you’re doing it the way you’re doing it.

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

Sidebar

Related Questions

So i have a piece of assembly that needs to call a function with
We have a moderate size (40-odd function) C API that needs to be called
I have a function that i need to call on iframe mousemove(). But i
I have an if statement that needs to look like this: UPDATE $(input#textbox).keypress(function(e){ key==e.which;
I have a win form that creates a site in IIS7. One function needs
I have 2 functions that needs to be executed one after the other. In
I have a servlet that needs a call like http://localhost:8080?a=1&a=3&a=2&b=5 . The thing is
Here's the deal: I have an Android application that needs to call a web
For a policy-based class-design I need some of the policies to call functions that
i have a function in a php web app that needs to get periodically

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.