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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:27:11+00:00 2026-05-27T17:27:11+00:00

I have a loop in Jquery: var fadeTime=500; css_id=0; $.each(my_array, function (i, d_U) {

  • 0

I have a loop in Jquery:

var fadeTime=500;
css_id=0;
$.each(my_array, function (i, d_U) {
css_id++;
an_v=d_U[1];
an_d=d_U[4];

do_c_function("id_344",true,true);

$("#box_"+css_id).fadeIn(fadeTime,function(){

   //this stuff will happen once the fadein is complete

   $("#box_"+css_id).animate({top: '-50px'},fadeTime,function(){

       //this stuff will happen once the animate is complete

       alert("#box_"+css_id);//for debugging

    });//end of animation

  });//end of fadein

});//end of each loop

Now as you’ve probably noticed, I’m trying to make the loop animate different divs each time using the css_id variable and ++; (add 1) to it each time the loop runs.

Thing is, css_id reaches a high value before any of the code below has even been executed once. So when its time to animate, Jquery will try to animate #box_210 when its supposed to animate #box_1.

Is there any way to make it only execute the css_id++; line once, then the animate lines get executed, and only then again with the css_id++; line…and so on.

I’ve tried to put the css_id++; line in a call back with both the animations but that seems to not work as well.

Thanks

  • 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-27T17:27:12+00:00Added an answer on May 27, 2026 at 5:27 pm

    Your animate callback function is forming a closure over css_id and therefore storing a live reference to css_id, not merely the value this variable holds at the moment the animation loop is created.

    Since all parameters are passed by value in JavaScript, you can use jQuery’s data function to break the closure, and take a snapshot of the css_id value at that time.

        $("#box_"+css_id).data("css_id", css_id).fadeIn(fadeTime,function(){
           var local_css_id = $(this).data("css_id");
           $("#box_"+ local_css_id).animate({top: '-50px'},fadeTime,function(){
    
               //this stuff will happen once the animate is complete
    
               alert("#box_" + local_css_id);//for debugging
            });//end of animation
          });//end of fadein    
        });//end of each loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a loop created with each, check this example: $('.foo').each(function(i){ //do stuff });
So, I have this jQuery .each loop, and for the most part its working
I have a very simple for-loop in jQuery: var iEra; for(iEra = 1; iEra
I have a jQuery issue I can't get past: (function ($) { var links
I have the following code in Javascript: jQuery(document).ready(function(){ var actions = new Object(); var
I have this jquery $('input#application_submit.bigbutton[value=Agree]').click(function(e){ e.preventDefault(); var reason = $('.agree_reason:visible'); var reason_text = $('.agree_reason:visible
I have a loop that reads each line in a file using getline() :
Need to run a for loop in jquery. Condition is : i have the
jQuery 1.4.2: I have an image. When the mouseover event is triggered, a function
I have a jQuery variable like this: var variable = $j(this).val(); Where $j(this) is

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.