Click the button to wait 3 seconds, then alert "Hello".
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> var myVar;//from www . ja v a 2 s.c o m function myFunction() { myVar = setInterval(alertFunc, 3000); } function alertFunc() { document.getElementById("demo").innerHTML += "Hello!"; } </script> </body> </html>