how to toggle visibility in a browser with javascript

from - thanx Arvind!

here is a javascript function to toggle visibility of page elements in a web browser. this can be put right after the <body> tag, etc:

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

to use, include something like this in a page:

  <a href="#" onclick="toggle_visibility('foo');">show/hide #foo</a>

  <div id="foo">This is foo</div>

to hide by default define an element like so:

<div id="foo" style='display:none;>This is foo</div>