Show and Hide Content Simple


Okay this is a tutorial on how to hide or show content on your website. Making your website much more interactive.

If any one wants to request an demo example of the script then please post a comment.

Okay heres the script...
JavaScript Code
  1. <script language="javascript" type="text/javascript">
  2. function toggle(item) {
  3. obj = document.getElementById(item);
  4. visible = (obj.style.display != "none");
  5. if(visible){
  6. obj.style.display = "none";
  7. } else {
  8. obj.style.display = "block";
  9. }
  10. }
  11. </script>
  12.  
  13. [<a onclick="toggle('blob');">show/hide</a>]
  14. <div id="blob">
  15. Huge amounts of text and images and php code here if you like. Tables, marquees all can be hidden when someone clicks show/hide.
  16.  
  17. Also you may need to adjust the show/hide link so it looks more like a link.
  18.  
  19. Thanks.
  20. </div>


Okay so thats simply all of it.
Try it out now, its pretty cool.
Thanks,

There shouldn't be any problems with it.
ilyas-shezad's Avatar
Views:
2,152
Rating:
Posted on Sunday 8th June 2008 at 09:12 AM
ilyas-shezad
ilyas-shezad's Avatar
Working code:
Code
<script language="javascript" type="text/javascript">

function toggle(item, toggler) {
obj = document.getElementById(item);
toggleitem = document.getElementById(toggler);
visible = (obj.style.display != "none");
if(visible){
obj.style.display = "none";
toggleitem.innerHTML = "Show";
} else {
obj.style.display = "block";
toggleitem.innerHTML = "Hide";
}
}
</script>

[<a onclick="toggle('blob', 'toggler1');" id="toggler1">Hide</a>]<br />
<div id="blob">
Huge amounts of text and images and php code here if you like. Tables, marquees all can be hidden when someone clicks show/hide.

Also you may need to adjust the show/hide link so it looks more like a link.

Thanks.
</div>
Posted on Sunday 8th June 2008 at 09:09 AM
ilyas-shezad
ilyas-shezad's Avatar
O sorry i did make an error 1 second im going to test it b4 i put up the working one.
Posted on Sunday 8th June 2008 at 09:08 AM
ilyas-shezad
ilyas-shezad's Avatar
Sure i guess so...
Just wrote the code out for you below...

Code
<script language="javascript" type="text/javascript">
function toggle(item, toggler) {
obj = document.getElementById(item);
toggleitem = document.getElementById(toggler);
visible = (obj.style.display != "none");
if(visible){
obj.style.display = "none";
toggler.innerHTML = "Show";
} else {
obj.style.display = "block";
toggler.innerHTML = "Hide";
}
}
</script>

[<a onclick="toggle('blob', 'toggler1');" name="toggler1>show/hide</a>]<br />
<div id="blob">
Huge amounts of text and images and php code here if you like. Tables, marquees all can be hidden when someone clicks show/hide.

Also you may need to adjust the show/hide link so it looks more like a link.

Thanks.
</div>


You can change as you like.
I havnt tested this code so report any errors please.
Posted on Sunday 8th June 2008 at 07:54 AM
Dalez
Dalez's Avatar
Cool, i'm using it now, but is there a way, that when the div is minimized, that a "+" comes up, and when its maximized a "-" comes up?

Thanks!
Posted on Friday 6th June 2008 at 06:46 PM
ashwill
ashwill's Avatar
Nice yes, but as SkillMaster has already said, it's more of a code snipper rather than a tutorial.
Posted on Friday 6th June 2008 at 06:46 AM
SkillMaster
SkillMaster's Avatar
Not really a tutorial, but a code snippet. Some explanation would be good ty.