I have a loop which should be updating a progress bar as the loop increments, however it's only colouring the progress bar in one go after the loop has actually finished. I remember having a similar problem, if I used alert statements, the colouring would work, so I think it has to do with the concurrency of threads. To solve my old problem, I used setTimeout. However, this still isn't getting my progress bar coloured in real-time.
Here's what I'm doing:
for (var i = 0; i < numOfRows; i++) {
setTimeout('ColourBlock(' + i + ')', 0);
// do_work
}
function ColourBlock (position){
document.getElementById("block" + position).style.backgroundColor = "orange";
}
Somebody told me it could be due to JavaScript optimization? Can anyone help please?