Useful JavaScript: Toggle Div Show/Hide

JavaScript: Show or Hide Elements

JavaScript: Show or Hide Elements

I was developing an e-commerce site today and I ran across a pretty light weight piece of JavaScript code to show and hide a DIVs.

Here it is:

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

Put that between your HEAD tags and call it from your code with “onClick=”.

Simple!

Tags: , , , , ,

Comments are closed.