Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-14-2009, 06:07 PM   PM User | #1
Zyprexa
New to the CF scene

 
Join Date: Apr 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Zyprexa is an unknown quantity at this point
Question 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; 04-14-2009 at 06:10 PM..
Zyprexa is offline   Reply With Quote
Old 04-14-2009, 06:17 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
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
oesxyl is offline   Reply With Quote
Old 04-14-2009, 06:39 PM   PM User | #3
Zyprexa
New to the CF scene

 
Join Date: Apr 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Zyprexa is an unknown quantity at this point
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>
Zyprexa is offline   Reply With Quote
Old 04-14-2009, 06:45 PM   PM User | #4
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
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.getElementById('hidethisone');
best regards
oesxyl is offline   Reply With Quote
Users who have thanked oesxyl for this post:
Zyprexa (04-14-2009)
Old 04-14-2009, 06:55 PM   PM User | #5
Zyprexa
New to the CF scene

 
Join Date: Apr 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Zyprexa is an unknown quantity at this point
Thumbs up solved

Worked like a charm!

Thanks alot!
Zyprexa is offline   Reply With Quote
Reply

Bookmarks

Tags
delay, div, hide, html, java

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:10 AM.


Advertisement
Log in to turn off these ads.