Monday, March 17, 2008

Content Show/Hide

I did a web job that I needed to show and hide content on a web page. For example (read more). After a lot of Google'n I found code which did the job:

Toggle navbar

Toggle BlogArchive1

Click here to toggle this


blah blah blah blah blah
blah blah blah blah blah
blah blah blah blah blah
blah blah blah blah blah
blah blah blah blah blah
blah blah blah blah blah
blah blah blah blah blah
blah blah blah blah blah




<a href="#" onclick="return toggle_visibility('foo');">Click here to toggle this</a>
<p id="foo">
blah blah blah blah blah
blah blah blah blah blah
blah blah blah blah blah
blah blah blah blah blah
</p>

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

</script>


Toggle Comments below

No comments: