I am completely unfamiliar with JS but i tried writing it using internet but for some reason i guess i am unable to connect my JS file to my HTML file or so for any reason the changes are not visible. The JS is for my navbar.
Below is the HTML code snippet of navbar
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- JS file -->
<script type="text/javascript" src="Styles/app.js"></script>
<!-- CSS file -->
<link rel="stylesheet" href="Styles/index.css" />
<!-- Icon file -->
<link
rel="stylesheet"
href="Assets/fontawesome-free-6.2.1-web/css/all.css"
/>
<title>Tea Station - Home</title>
</head>
<body>
<!-- navbar -->
<!-- nav items -->
<nav class="navbar" id="navbar">
<div class="navbar-header">
<span class="close-btn" id="nav-close">
<i class="fa-solid fa-xmark"></i>
</span>
</div>
<ul class="nav-items">
<li >
<a href="#" class="nav-links">home</a>
</li>
<li >
<a href="#" class="nav-links">skills</a>
</li>
<li >
<a href="#" class="nav-links">products</a>
</li>
<li >
<a href="#" class="nav-links">about</a>
</li>
</ul>
</nav>
<!-- nav button -->
<span class="nav-btn" id="nav-btn" >
<i class="fa-solid fa-bars"></i>
</span>
below is the code of the JS file
// setup date
const date = (document.getElementById("date").innerHTML =
new Date().getFullYear());
// setup nav
const navBtn = document.getElementById("nav-btn");
const navbar = document.getElementById("navbar");
const navClose = document.getElementById("nav-close");
// show nav
navBtn.addEventListener("click", () => {
navbar.classList.add("showNav");
});
// close nav
navClose.addEventListener("click", () => {
navbar.classList.remove("showNav");enter image description here
});
The navbar is supposed to open/displayed when the nav button is clicked but it isn't happening so. Since i am unfamiliar with JS i am unable to find out the cause.