Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Calling a Function Repeatedly with setInterval() Method</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> var myVar; function showTime(){ var d = new Date(); var t = d.toLocaleTimeString(); $("#demo").html(t); // display time on the page } function stopFunction(){ clearInterval(myVar); // stop the timer } $(document).ready(function(){ myVar = setInterval("showTime()", 1000); }); </script> </head> <body> <p id="demo"></p> <button onclick="stopFunction()">Stop Timer</button> </body> </html>