Last active
November 10, 2020 20:14
-
-
Save infoscigeek/1c721845fb46dd692e3bb86dccbb546a to your computer and use it in GitHub Desktop.
Toggle several divs
http://blogs.html5andcss3.org/show-and-hide-multiple-div-using-javascript/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var divs = ["Menu1", "Menu2", "Menu3", "Menu4"]; | |
var visibleDivId = null; | |
function toggleVisibility(divId) { | |
if(visibleDivId === divId) { | |
//visibleDivId = null; | |
} else { | |
visibleDivId = divId; | |
} | |
hideNonVisibleDivs(); | |
} | |
function hideNonVisibleDivs() { | |
var i, divId, div; | |
for(i = 0; i < divs.length; i++) { | |
divId = divs[i]; | |
div = document.getElementById(divId); | |
if(visibleDivId === divId) { | |
div.style.display = "block"; | |
} else { | |
div.style.display = "none"; | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment