Javascript examples for Browser Object Model:Window setInterval
Add wait or sleep command with setInterval() method
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){// ww w. j a va 2s. c o m var colors = ['red', 'green', 'blue'] var count = 0; setInterval(function () { document.body.style.backgroundColor = colors[count]; count ++ ; if(count >= colors.length){ count = 0; } },1000) } </script> </head> <body> </body> </html>