GeekIMO

GeekIMO *
Please login or register.

Login with username, password and session length
 

  • Home
  • Help
  • Search
  • Login
  • Register

  • GeekIMO »
  • Software »
  • Programming Discussion & Issues »
  • How Can I Hide a DIV until show is clicked
« previous next »
  • Reply
  • Print
Pages: 1   Go Down

Author Topic: How Can I Hide a DIV until show is clicked  (Read 554 times)

Offline Cloud

  • Administrator
  • Guest
  • Posts: 870
  • Geek-Ups: +14/-0
    • View Profile
    • Forge Team
How Can I Hide a DIV until show is clicked
« on: October 08, 2008, 06:20:05 PM »
  • Quote
Ok so Ive seen something on various site's where, well here it is, Example:

[What is cooking?]

They would click that and the [what is cooking?] would transform into
[Cooking is where you cook stuff] (HIDE)
and if they clicked hide it would transform back into [what is cooking?]

Anybody know how to do this? I don't want it to change page I just want it to change that text. When its clicked
« Last Edit: October 08, 2008, 07:56:48 PM by 1 »
Report to moderator   Logged

Offline i-CONICA

  • Administrator
  • Guest
  • Posts: 8
  • Geek-Ups: +0/-0
    • View Profile
    • FileQuake.com
Re: How Can I Hide a DIV until show is clicked
« Reply #1 on: October 08, 2008, 06:34:08 PM »
  • Quote
That's done with Javascript, One of the many millions of little cool things JavaScript can be used for.

Paste this into your html page right underneath the body tag of your document.

Code: [Select]
<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>
You can then call the above Java Script into action by passing the div ID to that code.
So the div id for the below code is cloud. It can be anything you like, As long as you change the onclick event to toggle visibility of the  ID cloud.

For example paste this into where ever you'd like the hide/show text to be. Placing the content you'd like to show or hide between the div tags.

Code: [Select]
<a href="#" onclick="toggle_visibility('cloud');">Toggle Visibility</a>
<div id="cloud">This is cooking with javascript!</div>

It'll have a similar effect to this
[hide]This is similar to what the above code will do, except this is only shown to members.[/hide]

Any Questions?  :)
Report to moderator   Logged

Offline Cloud

  • Administrator
  • Guest
  • Posts: 870
  • Geek-Ups: +14/-0
    • View Profile
    • Forge Team
Re: How Can I Hide a DIV until show is clicked
« Reply #2 on: October 08, 2008, 07:07:33 PM »
  • Quote
(!) problem: It shows when somebody enters the page, I want it to be hidden.
Report to moderator   Logged

Offline i-CONICA

  • Administrator
  • Guest
  • Posts: 8
  • Geek-Ups: +0/-0
    • View Profile
    • FileQuake.com
Re: How Can I Hide a DIV until show is clicked
« Reply #3 on: October 08, 2008, 07:53:37 PM »
  • Quote
Ok, More complex but try this.

Place this in the <head> of your page, so before the </head> tag.
Code: [Select]
<script type="text/javascript">
<!--
function setDivDisplay(value) {
   if(document.getElementById) {
      var nav1 = document.getElementById('showhideitem').style;
      nav1.display = value;
      return true;
   }
   return false;
}
function hide() {
   setDivDisplay("none");
}
window.onload = hide;
// -->
</script>

Then place this where you'd like it to be.
It can be anywhere in your <body>.
Code: [Select]
<a href="#" onclick="setDivDisplay('block');return false;">show</a>
<div id="showhideitem"><a href="#" onclick="setDivDisplay('none');return false;">hide</a><br />
Now this is cooking with javascript</div>

How's that?  ;)
Report to moderator   Logged

Offline Cloud

  • Administrator
  • Guest
  • Posts: 870
  • Geek-Ups: +14/-0
    • View Profile
    • Forge Team
Re: How Can I Hide a DIV until show is clicked
« Reply #4 on: October 08, 2008, 09:51:53 PM »
  • Quote
Works perfect! Thanks. But when you click show. Hide appears but show is still there. How can I remove show? while Hide is there?
Report to moderator   Logged

Offline i-CONICA

  • Administrator
  • Guest
  • Posts: 8
  • Geek-Ups: +0/-0
    • View Profile
    • FileQuake.com
Re: How Can I Hide a DIV until show is clicked
« Reply #5 on: October 08, 2008, 10:55:03 PM »
  • Quote
Not easily. That'll need a whole lot more code to do that, Unless I can come up with something quite simple, if not, it would be a block of code the length of your arm..

I'll ponder on it, see what i can do..  :o
Report to moderator   Logged

Offline Cloud

  • Administrator
  • Guest
  • Posts: 870
  • Geek-Ups: +14/-0
    • View Profile
    • Forge Team
Re: How Can I Hide a DIV until show is clicked
« Reply #6 on: October 08, 2008, 11:27:21 PM »
  • Quote
wow...that much!? Your example at the top is basically what I wanted.
Report to moderator   Logged

Offline i-CONICA

  • Administrator
  • Guest
  • Posts: 8
  • Geek-Ups: +0/-0
    • View Profile
    • FileQuake.com
Re: How Can I Hide a DIV until show is clicked
« Reply #7 on: October 08, 2008, 11:29:49 PM »
  • Quote
I'll ponder on it... :)
Report to moderator   Logged

Offline Cloud

  • Administrator
  • Guest
  • Posts: 870
  • Geek-Ups: +14/-0
    • View Profile
    • Forge Team
Re: How Can I Hide a DIV until show is clicked
« Reply #8 on: October 09, 2008, 08:34:10 PM »
  • Quote
gotcha ;)
Report to moderator   Logged

  • Reply
  • Print
Pages: 1   Go Up
« previous next »
  • GeekIMO »
  • Software »
  • Programming Discussion & Issues »
  • How Can I Hide a DIV until show is clicked
 

+ Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:

  • Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
  • Sitemap
  • RSS
  • WAP2

Page created in 0.099 seconds with 16 queries.