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

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 06-28-2012, 06:53 PM   PM User | #1
djnp
New to the CF scene

 
Join Date: Jun 2012
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
djnp is an unknown quantity at this point
Question Onclick show Image or DIV and hide automatically..

Hi, I am looking to show the image or DIV when clicked and hide it automatically (after specific time). It sounds like simple however I Googled for it but nothing found. So, I am hoping I will get something here in this genius JS programmers forum.

Any scripts example would be highly appreciated. (Please make it simple)


Thanks!!

Last edited by djnp; 06-28-2012 at 07:11 PM..
djnp is offline   Reply With Quote
Old 06-28-2012, 07:15 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 945
Thanks: 7
Thanked 97 Times in 97 Posts
WolfShade is an unknown quantity at this point
I don't completely follow. It has to be shown in order to be clicked, so it's already shown. You can automatically hide anything by using setTimeout("function",x); where x is the number of milliseconds (1000 per second) to call the function.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 06-28-2012, 08:28 PM   PM User | #3
djnp
New to the CF scene

 
Join Date: Jun 2012
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
djnp is an unknown quantity at this point
Quote:
Originally Posted by WolfShade View Post
I don't completely follow. It has to be shown in order to be clicked, so it's already shown. You can automatically hide anything by using setTimeout("function",x); where x is the number of milliseconds (1000 per second) to call the function.
Thanks for your response. I am new to JS as you can see the code below:

Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
function showArrow(o) {
	document.getElementById(o).style.display='block';
	setTimeout("showArrow()", 2000);
	}
</script>

<a href="javascript: showArrow('arrow');">show that arrow</a>
<div id="arrow" style="display:none; position: absolute; top: 50px; left: 50px;">↗</div>
I have tried above code and it works for showing the hidden DIV however it doesn't automatically hide the DIV. As I don't know where to specify following code for hiding the DIV?

Code:
document.getElementById(o).style.display='none';

Thanks!!

Last edited by djnp; 06-28-2012 at 08:33 PM.. Reason: to make it more clear
djnp is offline   Reply With Quote
Old 06-29-2012, 01:35 PM   PM User | #4
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 945
Thanks: 7
Thanked 97 Times in 97 Posts
WolfShade is an unknown quantity at this point
You placed the setTimeout that calls a function within the function, so it loops; every 2 seconds, it sets the display to "block".

To stop the setTimeout, you need to set it to a variable and use clearTimeout on the variable.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Users who have thanked WolfShade for this post:
djnp (06-29-2012)
Old 06-29-2012, 07:08 PM   PM User | #5
djnp
New to the CF scene

 
Join Date: Jun 2012
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
djnp is an unknown quantity at this point
Quote:
Originally Posted by WolfShade View Post
You placed the setTimeout that calls a function within the function, so it loops; every 2 seconds, it sets the display to "block".

To stop the setTimeout, you need to set it to a variable and use clearTimeout on the variable.
It would be really great if you could show, how to do it. Thanks much..
djnp is offline   Reply With Quote
Old 06-29-2012, 07:29 PM   PM User | #6
DaveyErwin
Regular Coder

 
Join Date: Aug 2010
Posts: 809
Thanks: 12
Thanked 168 Times in 166 Posts
DaveyErwin is on a distinguished road
Code:
<!doctype html>
<html>
<head><title></title>
</head>
<body>
<div onclick="var target=childNodes[1];target.style.display='block';setTimeout(function(){target.style.display='none'},2000)">
  clickme
  <img src="pic.jpg" style="display:none;"></div>
</body><html>

Last edited by DaveyErwin; 06-29-2012 at 07:37 PM..
DaveyErwin is offline   Reply With Quote
Users who have thanked DaveyErwin for this post:
djnp (06-29-2012)
Old 06-29-2012, 07:35 PM   PM User | #7
djnp
New to the CF scene

 
Join Date: Jun 2012
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
djnp is an unknown quantity at this point
Quote:
Originally Posted by DaveyErwin View Post
Code:
<doctype html>
<html>
<head><title></title>
</head>
<body>
<div onclick="var target=childNodes[1];target.style.display='block';setTimeout(function(){target.style.display='none'},2000)">
  clickme
  <img src="pic.jpg" style="display:none;"></div>
</body><html>
Genius!! thanks a lot!!
djnp is offline   Reply With Quote
Reply

Bookmarks

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 02:08 PM.


Advertisement
Log in to turn off these ads.