Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post

    Automatically hide div after several seconds

    I have a welcome message on my site and would like to automatically hide it after several seconds. I can't find anything usable after searching over the internet. Can anyone help?

    Thanks in advance.

  • #2
    Regular Coder Amphiluke's Avatar
    Join Date
    Jul 2009
    Posts
    312
    Thanks
    3
    Thanked 89 Times in 89 Posts
    Do you need help in searching over the internet?
    https://developer.mozilla.org/en/DOM/window.setTimeout
    I am still learning English

  • Users who have thanked Amphiluke for this post:

    levani (09-03-2009)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,920
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    You don't seem to have tried very hard!

    Code:
    <html>
    <head>
    
    <script type = "text/javascript">
    
    function hideMessage() {
    document.getElementById("message").style.display="none"; 
    }
    
    function startTimer() {
    var tim = window.setTimeout("hideMessage()", 5000);  // 5000 milliseconds = 5 seconds
    }
    
    </script>
    </head>
    
    <body onload = "startTimer()">
    
    <div id = "message" style="display:block">Welcome Message</div>
    
    </body>
    </html>

    BTW, the time to say "thanks" is afterwards, not beforehand which gives the - doubtless unintended - impression that you take other people's voluntary unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.

  • Users who have thanked Philip M for this post:

    levani (09-03-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •