First of all a little background so that you guys don´t respond so harshly, I´ve been learning code for the past month and a half. I´ve been having trouble hiding a window that shows up if your browser language is not in English. I know there are other ways to go around it but I would like to know why it isn´t working, I just don´t want to give up on it and try to understand it. I want the window to disappear when I press the no button. HERE IS AN IMAGE OF THE WINDOW https://imgur.com/gallery/iTEX0I0 Here is the code:
JavaScript
x
11
11
1
var lang = navigator.language;
2
if ("" + lang == "es-US") {
3
var div = document.getElementById("win");
4
}
5
var button = document.getElementById("buttonn")
6
buttonn.onclick = function() {
7
var div = document.getElementById("win");
8
if (div.style.display !== "none") {
9
div.style.display = "none";
10
}
11
}
JavaScript
1
20
20
1
<body>
2
<div class="container">
3
<div class="window" id="win">
4
<div class="layover">
5
<div class="h2">
6
<h2>Oops!</h2>
7
</div>
8
<div class="yesandno">
9
<figure class="yes">
10
<button onclick="window.location.href= 'espanol.html';">Si</button>
11
</figure>
12
<figure class="no">
13
<button onclick id="buttonn">No</button>
14
</figure>
15
</div>
16
<div class="langmessage">
17
Hemos detectado que el idioma de su ordenador se encuentra en español. ¿Le gustaría utilizar la versión en español de nuestro sitio web?
18
</div>
19
</div>
20
</div>
Advertisement
Answer
I think there’s a typo on line 6, change buttonn
to button, see if that works.
I have added the snippet that works fine, according to your need.
JavaScript
1
7
1
var button = document.getElementById("buttonn");
2
buttonn.onclick = function() {
3
var div = document.getElementById("win");
4
if (div.style.display !== "none") {
5
div.style.display = "none";
6
}
7
}
JavaScript
1
11
11
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<button type="button" id="buttonn">No</button>
6
<div id='win' style="height: 200px; width: 200px; border: 1px solid black"></div>
7
8
9
10
</body>
11
</html>