setinterval change background color code example
Example 1: javascript change background color setinterval
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);
Example 2: javascript change background color setinterval
<HTML>
<HEAD>
<TITLE>Using setInterval()</TITLE>
<SCRIPT LANGUAGE="JavaScript1.2"></SCRIPT>
</HEAD>
<BODY BGCOLOR="white">
<P>The setInterval() repeatedly changes the
document background color every three seconds.</P>
</BODY>
</HTML>