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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:44:03+00:00 2026-06-17T18:44:03+00:00

I am having trouble getting my jquery function to complete, before calling the next

  • 0

I am having trouble getting my jquery function to complete, before calling the next function.

Essentially, I am trying to get my news articles to fade out, and finish all the fadeout animations before then retrieving the next page of articles via ajax.

Heres what I have (Sampled to include only the functions concerned).

A function to control the fading out of each news article…

function fadeArticlesOut() {
    var delay = 0;
    //set timeout for image to appear (set at 500ms)
    $('#news-articles article').each(function(index) {
        $(this).delay(delay).fadeTo(800, 0);
        delay += 400;       
    })
};          

A function which is triggered by clicking a pagination link. This captures the url to load via ajax, but before it does so, this is where I want to run the fadeout function, i.e fadeArticlesOut. What I want is for the fade out animations to have finished before running the loadProducts function.

function doPager() {
    $('.pagination-controls a').click(function(e) {
        e.preventDefault();

        fadeArticlesOut();          
        loadProducts($(this).attr('href'));
        history.pushState(null, null, $(this).attr('href'));
        historyedited = true;
    });
}

function loadProducts(url) {
    $('#news-articles').empty().addClass('loading').load(url + ' #news-articles-inner', function() {
        $('#news-articles').removeClass('loading');
        doPager();
        fadeArticlesIn();
    });
}

Once completed, the load products function will then fade in the new news articles.

So far, I have tried numerous methods including using a custom callback, deferred objects and setting timeouts. The issue I have is I can either get it to run the fadeouts, but then not continue with the ajax content load, or not have the fadeouts, but get the ajax content.

  • 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-06-17T18:44:04+00:00Added an answer on June 17, 2026 at 6:44 pm

    You can get a promise by using .promise() and then add a .done() handler.

    function fadeArticlesOut() {
        ...
        return $('#news-articles article').each(function(index) {
          ...
        }).promise();
    };  
    

    function doPager() {
        $('.pagination-controls a').click(function(e) {
            var $self = $(this);
            ...
            fadeArticlesOut().done(function(){
                loadProducts($self.attr('href'));
            });          
            ...
        });
    }
    

    The .done() handler will be called upon all animations are completed.

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

Sidebar

Related Questions

having trouble calling a Jquery function from within PHP. I'm getting a syntax error
I'm having trouble getting the following JQuery script to function properly - its functionality
I'm having trouble getting jQuery's $(this) function to work as expected... or rather, to
I am trying to use the jquery autocomplete plugin but am having trouble getting
I'm having trouble getting this <div> to automatically update using jQuery. It's essentially a
I was having trouble getting a jQuery Ajax call's success function to work properly
I'm having trouble getting JQuery to load in IE7, works fine in all other
Super weird problem here. I'm having trouble getting jQuery to bind any selectors except
I'm having trouble getting the jQuery validation plugin to validate single input elements on
I'm having trouble getting the jquery ui 1.8 dialog to center I've tried leaving

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.