Web Analytics Made Easy -
StatCounter How do i hide a <div> after a delay? - CodingForum

Announcement

Collapse
No announcement yet.

How do i hide a <div> after a delay?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do i hide a <div> after a delay?

    I'm wondering if someone could help me out with a script that hides a <div> a couple of seconds after the page is loaded. I have little to no experience in Java, so i'm not sure how to go about it.
    Last edited by Zyprexa; Apr 14, 2009, 01:10 PM.

  • #2
    Originally posted by Zyprexa View Post
    I'm wondering if someone could help me out with a script that hides a <div> a couple of seconds after the page is loaded. I have little to no experience in Java, so i'm not sure how to go about it.
    java or javascript? if is java then you post in the wrong forum.

    with javascript you can do something like that:
    Code:
    function hideit(){
      var o = document.getElemenById('tohide');
      o.style.display = 'none';
    }
    window.onload = function(){
      setTimeout("hideit()",5000); // 5 seconds after user (re)load the page
    };
    in html you must have:
    Code:
    <div id="tohide">
    ......
    </div>
    not tested,

    best regards

    Comment


    • #3
      Could not get it to work

      Could not get this to work

      This is the code i tested:

      Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title>
      <script type="text/javascript">
      function hideit(){
        var o = document.getElemenById('hidethisone');
        o.style.display = 'none';
      }
      window.onload = function(){
        setTimeout("hideit()",5000); // 5 seconds after user (re)load the page
      };
      </script>
      
      </head>
      
      <body>
      <div id="hidethisone">
      THIS SHOULD VANISH
      </div>
      </body>
      </html>

      Comment


      • #4
        Originally posted by Zyprexa View Post
        Could not get this to work

        This is the code i tested:

        Code:
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitled Document</title>
        <script type="text/javascript">
        function hideit(){
          var o = document.getElemenById('hidethisone');
          o.style.display = 'none';
        }
        window.onload = function(){
          setTimeout("hideit()",5000); // 5 seconds after user (re)load the page
        };
        </script>
        
        </head>
        
        <body>
        <div id="hidethisone">
        THIS SHOULD VANISH
        </div>
        </body>
        </html>
        typo, missing a 't':
        Code:
          var o = document.getElemen[ICODE]t[/ICODE]ById('hidethisone');
        best regards

        Comment


        • #5
          solved

          Worked like a charm!

          Thanks alot!

          Comment

          Working...
          X