for(var i=0; i<barValues.length; i++) {
actualBarHeight = Math.floor((barValues[i]/chartMaxY)*barchartHeight);
var barChartID = "#barChart" + (i+1)
$(barChartID + " .value span").css('background-color','transparent');
$(barChartID + " img").animate({
height: actualBarHeight
}, 500, function(){$(barChartID + " .value span").css('background-color','white');}
);
$(barChartID + " .value span").html("$"+Math.floor(barValues[i]));
$(barChartID + " .value").css("bottom",actualBarHeight+"px");
$(barChartID + " .ylabel").html(chartMaxY);
};
The above bit of jQuery is inside a for loop. Each iteration of the loop does the following:
- sets the background of a span
- animates an object
- upon finishing, resets the background of the span
I'm using a call back function to reset the background so it finishes the animation before doing so. However, it only ends up affecting the last span referenced in the for loop.
If I move that bit of code outside of the callback, then it effects every span through every iteration of the for loop, (but doesn't wait for the animation in that case)
I'm guessing the issue has to do with building the selector INSIDE the function INSIDE the animate function. Is there some bad syntax in my markup?
EDIT (per Russ's suggestion, I now include the full loop in the above sample)