Hey there StackOverflow Community!
I’m fairly new to Stack and coding in general so this code will probably have an obvious error that I can’t figure out.
Basically, in the following code I want everything shown on screen that isn’t the element with the id settings
to be hidden.
JavaScript
x
4
1
if ((!"#settings").style.display === "block") {
2
$(!"#settings").hide();
3
}
4
HTML:
JavaScript
1
18
18
1
<body>
2
<span id="mainBtnArea">
3
<button id="settings-btn">Settings</button>
4
<button id="stats-btn">Stats</button>
5
</span>
6
<div id="mainArea">
7
<h1 id="clickHeader"></h1>
8
<button id="main-btn">Click Me</button>
9
</div>
10
<div id="settings">
11
<h1>this is the page I want to show</h1>
12
</div>
13
<div id="stats">
14
<p id="stats-clicks" class="stats">Keys:</p>
15
<p id="stats-keys" class="stats">Keys:</p>
16
</div>
17
</body>
18
Advertisement
Answer
JavaScript
1
7
1
var elements = document.getElementsByTagName('div');
2
for (var i = 0; i < elements.length; i++) {
3
if (elements[i].id != 'settings') {
4
elements[i].style.display = 'none';
5
}
6
}
7
You need to have a forloop! Update: You have to add an element tag DIV in order for it to work. Please see above.
It works for me: https://jsfiddle.net/bowtiekreative/j697okqd/1/