Prev Demo
Changing The Background Color Of The Page For Every Half Second In Javascript
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Changing background colors for every half second<h1> <p>Click the button to stop the color.</p> <input type="button" value="Stop" onclick="fixColor()"/> <script> var a = setInterval(function () { myColor() }, 500); function myColor() { var b = document.body; b.style.backgroundColor = b.style.backgroundColor == "lightgreen" ? "lightblue" : "lightgreen"; } function fixColor() { clearInterval(a); } </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output