Monday, August 08, 2005

Javascript: Display Toggle (Revised)

A simpler version of this script. Revised and improved:

<!-- JS: TOGGLE DISPLAY -->
<script type="text/javascript">
<!--

function toggle_display(element_id) {
if ( document.getElementById(element_id).style.display == 'none' ) {
document.getElementById(element_id).style.display = '';
} else {
document.getElementById(element_id).style.display = 'none';
}
return;
}

//-->
</script>
<!-- end JS: TOGGLE DISPLAY -->


Then call like so using the id you've given to the doc element:

<div id="toggle_block" style="background:blue;">now you see it</div>
<a onclick="toggle_display('toggle_block')" href="#toggle_block">show/hide</a>

1 Comments:

Anonymous Anonymous said...

thnx ..it helps me

10:01 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home