My images aren't updating immediately upon changing their src in javascript
Posted
by
Dale
on Stack Overflow
See other posts from Stack Overflow
or by Dale
Published on 2011-11-19T17:48:13Z
Indexed on
2011/11/19
17:50 UTC
Read the original article
Hit count: 371
I'm using the function below to change the img src. It's an array of ten images. When going through the loop, using break points, the images don't all update on the page immediately. Some of them do. If I inspect the unchanged images on the page (while paused at a breakpoint), the src has changed, but the image hasn't changed yet. All of the unchanged images get updated correctly when the function ends. Anyone know why they don't all get updated instantly and how I can force them to update? Also, is there a way I can hold off the updates of all of them until they're all reassigned and thus have them all update on the "simultaneously"? Here's my function.
function mainFunction(){
finalSet = calculateSet();
for ( var int = 0; int < finalSet.length; int++) {
var fileName = "cardImg" + (int);
document.getElementById(fileName).src = "images/cards/" + finalSet[int].name + ".jpg";
}
}
Thanks for the help. Dale
© Stack Overflow or respective owner