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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:26:05+00:00 2026-05-25T22:26:05+00:00

The following snippet works as expected: function boxAnimation() { var dfd = $.Deferred(); $(‘div’).fadeIn(‘slow’,

  • 0

The following snippet works as expected:

function boxAnimation() {
        var dfd = $.Deferred();
        $('div').fadeIn('slow', dfd.resolve);            
        return dfd.promise();
    }

    $(function () {
        boxAnimation().done(
            function () { $(this).animate({ 'margin-top': 50 }); },
            function () { $(this).animate({ 'margin-left': 150 }); },
            function () { $(this).animate({ 'margin-top': 250 }); },
            function () { $(this).animate({ 'margin-left': 350 }); }
        ).fail(function () { alert('failed'); });
    });

However in this one the differed object is neither rejected or resolved.

Please tell me where am I going wrong.

function boxAnimation() {
        var dfd = $.Deferred();
        var randomNum = Math.floor(Math.random() * 5);
        $('div').fadeIn('slow', function () {
            if (randomNum == 1) {
                dfd.reject;
            }
            else {
                dfd.resolve;
            }
        });            
        return dfd.promise();
    }

    $(function () {
        boxAnimation().done(
            function () { $(this).animate({ 'margin-top': 50 }); },
            function () { $(this).animate({ 'margin-left': 150 }); },
            function () { $(this).animate({ 'margin-top': 250 }); },
            function () { $(this).animate({ 'margin-left': 350 }); }
        ).fail(function () { alert('failed'); });
    });

my body is:

<div id='box' style='width:200px; height:200px; border:solid 1px #222222; display:none; background:#cccccc'></div>
  • 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-25T22:26:06+00:00Added an answer on May 25, 2026 at 10:26 pm

    You should call functions; currently you’re accessing them and leaving them untouched. By actually calling reject/resolve, you are really rejecting/resolving things.

    In the fadeIn in the first example, you passed it without (). This is correct, because you should leave it untouched at that point. jQuery will internally call the function when the animation is done.

    Since in the second example the calls are already in a function that is executed when the animation is done, you should call them at that point.

    if (randomNum == 1) {
        dfd.reject();      // '()' calls a function
    }
    else {
        dfd.resolve();
    }
    

    Secondly, inside a done handler, this is the Deferred object. If you want to pass the div, you can do so by passing it when rejecting/resolving: http://jsfiddle.net/PrmQR/1/.

    function boxAnimation() {
        var dfd = $.Deferred();
        var randomNum = Math.floor(Math.random() * 5);
        $('div').fadeIn('slow', function () {
            if (randomNum == 1) {
                dfd.reject(this);    // pass div
            }
            else {
                dfd.resolve(this);
            }
        });            
        return dfd.promise();
    }
    
    $(function () {
        boxAnimation().done(
            function (x) { $(x).animate({ 'margin-top': 50 }); },     // x is the div
            function (x) { $(x).animate({ 'margin-left': 150 }); },
            function (x) { $(x).animate({ 'margin-top': 250 }); },
            function (x) { $(x).animate({ 'margin-left': 350 }); }
        ).fail(function () { alert('failed'); });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code snippet: $.getJSON(http://localhost:8080/images, function(data) { var items = []; $.each(data,
I am trying to convert the following JS snippet to CoffeeScript: $(document).ready(function(){ window.setTimeout(function(){ $('#flash').slideUp('slow',
I have the following snippet which works as expected: <a href=http://google.com onclick=return false;>Will go
I have the following snippet of code: $('input#teamName').live('blur', function() { var value = $(this).val();
Never thought I'd have this problem :) The following snippet of code works in
I have the following snippet in one of my html pages : <div class=inputboximage>
The following code snippet works fine for CSV file sizes larger than 10 K.
I have the following snippet that works fine on Heroku (production) for enforcing SSL:
The following snippet, from another thread, works to print a message and fail after
I have the following WordML snippet which works well for numbered lists : <w:wordDocument

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.