12
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 another menu the previous submenu closes? Currently both are getting 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>
Works Perfectly. Only it has a detail when updating does not come back with the previous menu that is Selected.
– Luquinhas Brito