dropfaith Posted August 31, 2008 Share Posted August 31, 2008 How would i make this so if theres more then one menu click on them closes all other open menus http://dropfaithproductions.com/test/blogs.php its live there i just need it so you can only have one menu open at a time function showElement(layer){ var myLayer = document.getElementById(layer); if(myLayer.style.display=="none"){ myLayer.style.display="block"; myLayer.backgroundPosition="top"; } else { myLayer.style.display="none"; } } <li><a href="#" class="button" onclick="javascript:showElement('v-menu2')">Links</a> <ul id="v-menu2" class="v-menu2" style="display:none;"> Link to comment https://forums.phpfreaks.com/topic/122066-solved-show-hide-menus/ Share on other sites More sharing options...
Ken2k7 Posted August 31, 2008 Share Posted August 31, 2008 What are the menus? The way would be to loop through and find the menus that are open and close them, leaving the one you selected to be open. Link to comment https://forums.phpfreaks.com/topic/122066-solved-show-hide-menus/#findComment-630186 Share on other sites More sharing options...
dropfaith Posted August 31, 2008 Author Share Posted August 31, 2008 im new tpo javascript the menus are for blogs links and gallerys http://dropfaithproductions.com/test/index.php Link to comment https://forums.phpfreaks.com/topic/122066-solved-show-hide-menus/#findComment-630187 Share on other sites More sharing options...
Ken2k7 Posted August 31, 2008 Share Posted August 31, 2008 Give this a try: function showElement (layer){ var hideOthers = document.getElementsByTagName("ul"), hlen = hideOthers.length; while (--hlen > -1) { var tehElem = hideOthers[hlen]; if (tehElem.id !== undefined && tehElem.id != layer && tehElem.className == "v-menu" && tehElem.style.display != "none") tehElem.style.display = "none"; } var myLayer = document.getElementById(layer); if (myLayer.style.display == "none") { myLayer.style.display = "block"; myLayer.backgroundPosition = "top"; } else { myLayer.style.display="none"; } } Link to comment https://forums.phpfreaks.com/topic/122066-solved-show-hide-menus/#findComment-630218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.