Javascript examples for Browser Object Model:Window clearInterval
Window clearInterval() Method - Toggle between two background colors once every 300 milliseconds, until it is stopped by clearInterval():
<!DOCTYPE html> <html> <body> <button onclick="stopColor()">Stop Toggling</button> <script> var myVar = setInterval(function(){ setColor() }, 300); function setColor() {// w w w .j a va2 s . c o m var x = document.body; x.style.backgroundColor = x.style.backgroundColor == "yellow" ? "pink" : "yellow"; } function stopColor() { clearInterval(myVar); } </script> </body> </html>