Mahmoud Santos
22 Feb 2022
Javascript
How to Set two background-color in the javascript by setInterval( )?
let x = document.body;
x.style.backgroundColor = x.style.backgroundColor === "yellow" ? "pink": "yellow";
Yasen Sayed
22 Feb 2022
Best Answer
Try this approach,
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>
© 2024 Copyrights reserved for web-brackets.com