The toggle functionality in the Menu is not working properly. Upon clicking the toggle button, I encountered the following JavaScript error:
"message": "Uncaught TypeError: Cannot read property 'toggle' of undefined",
"filename": "https://stacksnippets.net/js",
"lineno": 159,
"colno": 44
}
//java.js
function toggleMenu() {
document.getElementById('Menu').classlist.toggle('active');
}
* {
margin: 0px;
padding: 0px;
font-family: sans-serif;
}
#Menu {
padding: 0px;
position: fixed;
width: 400px;
height: 100%;
background: #00ff00;
left: -400px;
}
#Menu.active {
display: 0px;
}
#menu ul li {
color: rgba(230, 230, 230, 0.9);
list-style: none;
padding: 15px 10px;
top: 40px;
position: relative;
width: 200px;
vertical-align: middle;
cursor: pointer;
background-color: #00ff00;
border-top: 4px solid #ff0000;
-webkit-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
#Menu .toggle-btn {
position: absolute;
left: 410px;
top: 65px;
}
#Menu .toggle-btn span {
display: block;
width: 30px;
height: 5px;
background: #000;
margin: 5px 0px;
}
#menu ul {
list-style: none;
margin: 0px;
padding: 0;
}
#menu ul li:hover {
background-color: #000;
}
#menu>ul>li {
border-right: 4px solid #ff0000;
border-left: 2px solid #000;
}
.bottom {
border-bottom: 4px solid #ff0000;
}
#menu ul ul {
transition: all 0.3s;
opacity: 0;
position: absolute;
border-left: 4px solid #ff0000;
border-bottom: 4px solid #ff0000;
border-right: 4px solid #ff0000;
visibility: hidden;
left: 100%;
top: -2%;
}
#menu ul li:hover>ul {
opacity: 1;
visibility: visible;
}
#Menu ul li a {
text-decoration: none;
}
i {
margin-left: 15px;
}
#menu>ul>li:nth-of-type(3)::after {
content: "+";
position: absolute;
margin-left: 60%;
color: #fff;
font-size: 18px;
}
#menu>ul>li:nth-of-type(2)::after {
content: "+";
position: absolute;
margin-left: 56%;
color: #fff;
font-size: 18px;
}
<!doctype html>
<html>
<head>
<title>vertical menu with css</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<script src="java.js"></script>
</head>
<body>
<div id="Menu">
<div class="toggle-btn" onclick="toggleMenu()">
<span></span>
<span></span>
<span></span>
</div>
<ul>
<li><a href="#"><i class="fas fa-home">Home</i></a></li>
<li><a href="#"><i class="fas fa-user-tie">Bjorn</i></a>
<ul>
<li><a href="#">Child 1 </i></a></li>
<li><a href="#">Child 2 </i> </a></li>
<li><a href="#">Child 3 </i></a></li>
</ul>
<li><a href="#"><i class="fas fa-user">Cille</i></a>
<ul>
<li><a href="#">Child 1 </a></li>
<li><a href="#">Child 2 </a></li>
<li><a href="#">Child 3 </a></li>
</ul>
<li><a href="#"><i class="fas fa-user-tie">David</i></a></li>
<li class="bottom"><a href="#"><i class="fas fa-user-tie">Fin</i>/a></li>
</ul>
</div>
</body>
</html>