Javascript Browser Window setInterval() Method display message

Introduction

Click the button to wait 3 seconds, then alert "Hello".

View in separate window

<!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>



PreviousNext

Related