I have the script below to use in a menu. It changes the visibility of a specific element by its ID. Clicking on a main menu opens a submenu.
Is there any way to change the script so that when clicking on another menu the previous submenu close? They are currently getting both open.
<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>
<a href="#" onclick="toggle_visibility('menu1');">
<p>Menu Um</p>
</a>
<div id="menu1" style="display:none;">
<ul>
<li>Item Um</li>
<li>Item Dois</li>
<li>Item Três</li>
</ul>
</div>
<a href="#" onclick="toggle_visibility('menu2');">
<p>Menu Dois</p>
</a>
<div id="menu2" style="display:none;">
<ul>
<li>Item Um</li>
<li>Item Dois</li>
<li>Item Três</li>
</ul>
</div>