Using sublime text 3, javascript won't work in browsers, to work my hamburger/toggle menu. script5009 error occurs $ not defined
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" type="text/css" href="CSS/style.CSS">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="/JS/stuff.js"></script>
</head>
<body>
<header>
<div class="container">
<h1 class="Logo"><img src="images/image.png"></h1>
<nav class="site-nav">
<ul>
<li><a href="">Home</a></li>
<li><a href="">About us</a></li>
<li><a href="">staff</a></li>
<li><a href="">Contact</a></li>
</ul>
</nav>
<div class="menu-toggle">
<div class="hamburger"></div>
</div>
</div>
</header>
</body>
</html>
Your problem is that you don't have the jQuery script. Add this tag to the top of the file:
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
And it will work.
Add this code to your HTML to toggle the hamburger:
$(".menu-toggle").on("click", () => {
$(".hamburger").toggle();
});
And it'll work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.