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;"> Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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"; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.