JavaScript setTimeout()

JavaScript setTimeout() function used to repeats the execution of the function continuously. Another word we can say that JavaScript setTimeout() function use to create a timing events.

Here is the example when click on button after 2 second alert box will be open.

JavaScript setTimeout() Function


var time=setTimeout("javascript_statement", milliseconds);


<!DOCTYPE html>
<html lang="en">
  <title>JavaScript setTimeout with Alert Box</title>

<script type="text/javascript">
    function tMessage() {
        var time=setTimeout("alert('When you click press, Alert box will open in 2 seconds.')", 2000);

    <input type="button" value="Open Alert Box" onClick="tMessage()"/>


Run it...   »

Example Result