Prev Demo
Stop Changing The Background Color Using Clearinterval Method.
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Stop changing the background color</h1> <p>Click the button to stop changing the background color 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