JavaScript

Show a DIV after X seconds in Javascript

In this tutorial, we are going to see how to show a DIV after X seconds in Javascript. In the example below, we will see how to display div1 after 15 seconds and display div2 after 30 seconds.
 

Script to Show a DIV after X seconds in Javascript
<html>
   <body>
    <div id="div1" style="visibility: hidden">
        Show a DIV after 15 seconds.
    </div>
    <div id="div2" style="visibility: hidden">
        Show a DIV after 30 seconds.
    </div>
   </body>
   <script type="text/javascript">
    function showDiv1() {
      document.getElementById("div1").style.visibility = "visible";
    }
    setTimeout("showDiv1()", 15000); // after 15 sec

    function showDiv2() {
      document.getElementById("div2").style.visibility = "visible";
    }
    setTimeout("showDiv2()", 30000); // after 30 secs
   </script>
</html>
Result
[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

One thought on “Show a DIV after X seconds in Javascript

  • Ahmed Cherif

    thank you very much for this precious article

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *