I've organized my code with a separate HTML file for the header section. The index file, where I've included all the necessary links to Bootstrap, appears as follows:
<head>
...
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css "/>
</head>
<body>
<header>
<script>
document.addEventListener("DOMContentLoaded", function () {
fetch('header.html')
.then(response => response.text())
.then(data => {
document
.querySelector('header')
.innerHTML = data;
})
})
</script>
</header>
.....
script src="https://cdn.jsdelivr.net/npm/popper.js@2.11.6/dist/umd/popper.min.js"
integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js"
integrity="sha384-BBtl+eGJRgqQAUMxJ7pMwbEyER4l1g+O15P+16Ep7Q9Q+zqX6gSbd85u4mG4QzX+"
crossorigin="anonymous"></script>
</body>
Additionally, here is the content of my header.html file:
<nav class="navbar navbar-expand-lg">
<div class="container-fluid">
<a class="navbar-brand" href="https://">Lorem Ipsum</a>
<button class="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarNavDropdown"
aria-controls="navbarNavDropdown"
aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="./#about-us">about</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./#services">services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./#team">team</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./#contacts">contact</a>
</li>
</ul>
</div>
</div>
</nav>
Currently, when I click the burger icon to open the menu, it stays open even after another click. Could this issue be due to the separate file for the navbar?