Javascript Browser Window setTimeout() Method with named function

Introduction

You can also refer to "named" function;

Display an alert box after 3 seconds, 3000 milliseconds:

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  w ww. j a  v a  2 s  .  co  m

function myFunction() {
  myVar = setTimeout(alertFunc, 3000);
}

function alertFunc() {
  document.getElementById("demo").innerHTML +="Hello!";
}
</script>

</body>
</html>



PreviousNext

Related