I'm confused about how to use the setTimeout function within a for loop. What I'm trying to do is highlight divs one at a time based on an array. Here's my code:
for (i = 0; i < strArray.length; i++) {
doSetTimeout(i, colors, strArray);
}
and then the function, doSetTimeout:
function doSetTimeout(i, colors, strArray) {
$("use." + strArray[i]).css("fill", colors[Math.floor((Math.random() * colors.length) + 1)]);
setTimeout(function() {
$("use").css("fill", "#333333");
}, 1000);
}
Based on this thread, I thought having a separate function to do the color changing would solve the problem, but I'm still having an issue where all of the divs flash at the same time. Anyone know what the issue might be? And is there another, preferable way to do this?