Hide and show DIV (Javascript)

by spyka (http://www.spyka.net)

This little javascript script will allow you to toggle the showing of a div via a link. The html included shows an example of how to use it.

Code:
<!-- Place in <head></head> tags --> 
<script type="text/javascript">
<!--
function toggle_div(id) {
    var diq = document.getElementById(id).style;
    diq.display=(diq.display=="none") ? "" : "none";

}
//-->
</script>

<!-- Example usage -->
<a href="javascript:toggle_div('hideshow')">Hide/show</a>

<div id="hideshow">
    <h1>Example</h1>
</div>

Code demo

Hide and show DIV online demo

Help and comments

Discuss this and other scripts in our webmaster foruns

Learn more about our forums