I am trying to write a JavaScript function that will hide multiple IDs at once. As I will be getting into 50 or so IDs that will need to be hidden for any given function, I don't want to have unnecessary code. I have something like below, but there must be a way to combine all these lines in to one, no?
document.getElementById("aMap").style.display = "none";
document.getElementById("aList").style.display = "none";
document.getElementById("bMap").style.display = "none";
document.getElementById("bList").style.display = "none";
document.getElementById("cMap").style.display = "none";
document.getElementById("cList").style.display = "none";
Ok, thanks everyone. Showing my updated code below. It's not working, as I am sure I am doing something wrong. The goal is to have a function that shows 2 elements that are identified by ID and hide all of the other IDs at the same time:
function zShowHideRest() {
var zOther = ["aMap", "aList", "bMap", "bList", "cMap", "cList"];
zOther.forEach.getElementById().style.display = "none";
document.getElementById("zMap").style.display = "block";
document.getElementById("zList").style.display = "block";
}
Am I in the ballpark or is what I did way off?
forEach.