I just started to make this page, to practice, when I ran into this error, that the .s1episodes
div should appear with the onmouseover
command, hovering the .season1
div, but it doesn't, although I've done this before multiple times and it has always worked.
As you can see, the error message is: "Cannot read property 'display' of undefined". I'm a beginner still, so I'm not really aware of the meaning of this.
I've seen other questions with this error message, but they didn't help me unfortunately.
Why is this not working this time?
function showseason1() {
var S1 = document.getElementsByClassName("s1episodes");
S1.style.display = (S1.style.display === 'block' ? 'none' : 'block');
}
/* # */
body {
background-color: #38ADAE;
color: #CD295A;
max-width: 1900px;
max-height: 1500px;
}
.menu {
position: fixed;
position: absolute;
left: 13%;
width: 70%;
height: 35%;
background-color: #9B2027;
color: #CC4E13;
}
#logo {
height: 100%;
}
.about {
top: 0%;
width: 10%;
height: 99%;
position: absolute;
left: 5%;
}
.cast {
top: 0%;
width: 10%;
height: 99%;
position: absolute;
left: 20.1%;
}
.season1 {
z-index: 2;
top: 0%;
width: 10%;
height: 99%;
position: absolute;
left: 35.2%;
}
.season2 {
top: 0%;
width: 10%;
height: 99%;
position: absolute;
left: 45.3%;
}
.season3 {
top: 0%;
width: 10%;
height: 99%;
position: absolute;
left: 55.4%;
}
.season4 {
top: 0%;
width: 10%;
height: 99%;
position: absolute;
left: 65.5%;
}
#season1,
#season2,
#season3,
#season4 {
margin-left: -13px;
}
.titles {
font-weight: bold;
font-size: 25px;
position: absolute;
top: 37%;
left: 25%;
}
.s1episodes {
text-align: center;
border-radius: 15px;
display: none;
position: absolute;
width: 70%;
height: 350%;
border: 3px solid red;
bottom: -360%;
left: 3%;
}
h2 {
text-align: center;
}
button {
font-size: 19px;
border: none;
background-color: transparent;
color: #291A14;
}
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="TFS.css" />
<script src="TFS.js"></script>
</head>
<body>
<div class="menu">
<img id="logo" src="logo.jpg" />
<div class="about">
<span class="titles">About</span>
</div>
<div class="cast">
<span class="titles">Cast</span>
</div>
<div class="season1" onmouseover="showseason1()">
<span id="season1" class="titles">S1</span>
</div>
<div class="s1episodes">
<h2>Episode List</h2>
<button>Episode 1</button>
</div>
<div class="season2">
<span id="season2" class="titles">S2</span>
</div>
<div class="season3">
<span id="season3" class="titles">S3</span>
</div>
<div class="season4">
<span id="season4" class="titles">S4</span>
</div>
</div>
</body>
</html>