I wrote code on JavaScript, it suppose to give class "active" to the sidebar when clicking on the hamburger menu, but it isn't. It says that "hamburger is not defined or it's not a function". I checked everything I could but could not find the answer.
Here is the HTML code:
const hamburger = document.getElementsByClassName(".hamburger");
const sidebar = document.getElementsByClassName(".sidebar");
hamburger.addEventListener('click', () => {
sidebar.classList.add("active");
})
.main-page {
width: 100%;
height: 100vh;
background-color: #000;
display: flex;
flex-direction: column;
justify-content: center;
}
.main-page__inner {
width: 100%;
max-width: 1350px;
margin: 0 auto;
}
.main-page__title {
font-family: 'Syncopate';
font-style: normal;
font-weight: 700;
font-size: 100px;
line-height: 104px;
color: #FFFFFF;
}
.hamburger {
position: absolute;
width: 40px;
top: 69px;
left: 41px;
z-index: 9999;
padding: 15px 0;
cursor: pointer;
}
.hamburger__item {
width: 100%;
display: block;
height: 4px;
background-color: #fff;
position: absolute;
inset: 0;
margin: 0 auto;
}
.hamburger__item:before,
.hamburger__item:after {
width: 100%;
height: 4px;
position: absolute;
content: "";
background-color: #fff;
left: 0;
z-index: 9999;
}
.hamburger__item:before {
top: -7px;
}
.hamburger__item:after {
bottom: -8px;
}
.sidebar {
position: fixed;
top: 0;
left: -100%;
bottom: 0;
z-index: 600;
background: #591753;
width: 100%;
max-width: 400px;
height: 100vh;
visibility: hidden;
}
.sidebar.open {
visibility: visible;
left: 0;
}
.sidebar__inner {
display: flex;
align-items: center;
justify-content: center;
margin: auto 0;
}
.sidebar__title {
font-family: 'Montserrat';
font-weight: 400;
font-size: 20px;
color: #fff;
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&family=Montserrat:wght@400;600&family=Open+Sans:wght@300;400;500;600;700;800&family=Raleway:wght@100;200;300;400;500;600;700;800;900&family=Source+Sans+Pro:wght@600&family=Syncopate:wght@400;700&display=swap"
rel="stylesheet">
<header class="header">
<div class="container">
<div class="header__inner">
<div class="nav-bar">
<img class="logo" src="/assets/Header/LOGO.png" alt="logo">
<a class="click-to-action" href="#">Оставить заявку</a>
</div>
</div>
</div>
</header>
<div class="hamburger" id="hamburger">
<span class="hamburger__item" id="hamburger__item"></span>
</div>
<div class="sidebar" id="sidebar">
<div class="sidebar__inner">
<h1 class="sidebar__title">BLA BLA BLA</h1>
</div>
</div>
<div class="main-page">
<div class="container">
<div class="main-page__inner">
<h1 class="main-page__title">CHAMPION ASTANA</h1>
</div>
</div>
</div>