postimg
Oct 2008 15

Simple Toggle Visibility0

Posted In JavaScript By Tony Virelli

This is a simple toggle visibility or show/hide function. I use it all the time.

First insert this function into the head section:

<script type="text/javascript">// <![CDATA[
 function toggle_visibility(id) {     var e = document.getElementById(id);     if(e.style.display == 'block'){         e.style.display = 'none';     }else{        e.style.display = 'block';     } }
// ]]>
</script>

Then use the code below to call the function:

<a onclick="toggle_visibility('foo');" href="#">Click here to toggle visibility of element #foo</a>
<div id="foo">This is foo</div>
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • email
  • LinkedIn
  • MySpace
  • PDF
  • Reddit
  • RSS
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter

Leave a comment

Get Adobe Flash playerPlugin by wpburn.com wordpress themes