97
rated 0 times
[
103]
[
6]
/ answers: 1 / hits: 38160
/ 9 Years ago, thu, september 17, 2015, 12:00:00
function change(i) {
var doc = document.getElementById(background);
var color =[ black, blue, brown, green];
for(i=0; i<color.length; i++){
doc.style.backgroundColor = color[i];
alert(my color is + color[i]);
/*if (i>=color.length){i=0;}*/
}
}
setInterval(function changebackground(){change(0)},1000);
HI Folks,
I am trying to change the background color of a div using the code above. The function works as long as the alert is part of it (I introduced the alert to see if the loop was working ). How do I get the function working without the alert. I need to use vanilla js not jquery. Thanks for helping a beginner.
More From » javascript