Showing and hiding, or ‘toggling’ elements is one of the most common tasks in javascript. Here’s a great resource that shows 7 different ways to do this:
My personal favorite is the ternary operator:
[code lang="javascript"]function toggle(obj) {
var el = document.getElementById(obj);
el.style.display = (el.style.display != 'none' ? 'none' : '' );
}[/code]
You can adjust your examples to use display:none/display:block or visibility:hidden/visibility:visible, which have slightly different ways of rendering.