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>






