how to toggle visibility in a browser with javascript

from http:_blog.movalog.com/a/javascript-toggle-visibility/ - 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(e.style.display == 'block')
                  e.style.display = 'none';
           else
                  e.style.display = 'block';
        }
  _-->
  </script>

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>