set over two background-color in javascript setInterval()
let x = document.body; x.style.background-Color = x.style.background-Color == "yellow" ? "pink": "yellow";
CodePudding user response:
Try this:
var i = 0;
function change() {
var doc = document.getElementById("background");
var color = ["black", "blue", "brown", "green"];
doc.style.backgroundColor = color[i];
i = (i 1) % color.length;
}
setInterval(change, 1000);
<div id="background"> </div>