Time Delayed action

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KeredDrahcir
    Contributor
    • Nov 2009
    • 426

    Time Delayed action

    I want a division to be made visible three seconds after the page loads but nothing seems to be happening. Am I using the right code?
    I'd rather not have to use a function if I can avoid it.
    Code:
    <body onload="setTimeout(document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block', 3000)">
    Thanks for any help.
  • Bharat383
    New Member
    • Aug 2011
    • 93

    #2
    Code:
    <script type="text/javascript">
    function start_page()
    {
      setTimeout("display_div()",3000);
    }
    
    function display_div()
    {
       document.getElementById('div_id').style.display="block";
    }
    </script>
    <body onload = "start_page()">
    <div id="div_id"> this is div content which is display after 3 seconds.</div>
    </body>
    Last edited by Dormilich; May 8 '12, 06:24 AM. Reason: Please use [CODE] [/CODE] tags when posting code.

    Comment

    • KeredDrahcir
      Contributor
      • Nov 2009
      • 426

      #3
      I'll give that a go tonight. Thanks.

      By the way, would it work if I put the functions in a seperate js file or does it need to be on the page?

      Comment

      • Bharat383
        New Member
        • Aug 2011
        • 93

        #4
        yes... you can put on separate js file but you must have to link that file.

        Comment

        • KeredDrahcir
          Contributor
          • Nov 2009
          • 426

          #5
          Okay. I'll give that a go and get back to you on what happens.

          Comment

          • KeredDrahcir
            Contributor
            • Nov 2009
            • 426

            #6
            Thanks. It worked perfectly. That's brilliant. Just out of interest, is it possible to do it without functions?

            Comment

            Working...