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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:05:40+00:00 2026-05-28T04:05:40+00:00

If you select a class or collection of elements to animate with jQuery: $(‘.myElems’).animate({….});

  • 0

If you select a class or collection of elements to animate with jQuery:

$('.myElems').animate({....});

And then also use the callback function, you end up with a lot of unneccessary animate() calls.

var i=1;
$('.myElems').animate({width:'200px'}, 200, function(){
    //do something else
    $('#someOtherElem').animate({opacity:'1'}, 300, function(){        
        if (i>1) console.log('the '+i+'-th waste of resources just finished wasting your resources');
        i++;
    });
});

Arguably this is just bad code and / or design – but is there something I can do that both avoids having many animate() calls with only one of them using the callback, and having a load of unneccessary callbacks executing and screwing with my code / expected behaviour?

Ideally I’d just be able to code a single ‘disposable’ callback that will only run once – otherwise perhaps there is an efficient way to test if something is already being animated by jQuery?

Example: http://jsfiddle.net/uzSE6/ (warning – this will show a load of alert boxes).

  • 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-28T04:05:41+00:00Added an answer on May 28, 2026 at 4:05 am

    You could use when like:

    $.when($('.myElems').animate({width: 200}, 200)).then(function () {
      console.log('foo');
    });
    

    http://jsfiddle.net/tyqZq/

    Alternate version:

    $('.myElems').animate({width: 200}, 200).promise().done(function () {
      console.log('foo');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to select next n hidden elements that have class foo using jQuery?
Is it possible to use the OpenFileDialog class select a file OR folder? It
I have a collection of div elements that have the class media-gallery-item . I
I'm trying to select all elements that have a given class and remove them
How can I set a select class and other attributes eg:events through the SelectList
Overall Plan Get my class information to automatically optimize and select my uni class
How can I select an object's class in HQL? When I do the following:
I've written a class that contains Select- and Update-Methods for an ObjectDataSource. The UpdateMethod
I'm using the OpenFileDialog class so a user can select an image file. I'd
I have a DAO class which I'm using to try select/update/insert with hibernate and

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.