I currently have a site where I want to create a navigation bar where when I add a page to the nav bar, it will automatically add it to all pages that I have currently uploaded to my site.
I currently have a script for a “Back to Top” button as well as a script for a responsive navigation bar. I’m now looking to add a script that will load the nav bar from another HTML page that contains my actual nav bar. But for some reason, even after adding the script, the nav bar isn’t loading for some reason.
Below is my main index.html page that contains all the scripts:
<!doctype html>
<html lang="en-US">
<head>
<title>Title</title>
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script src="https://kit.fontawesome.com/0a48c3a8e0.js" crossorigin="anonymous"></script>
<script>
$(document).ready(function() {
$("#nav-placeholder").load("nav.html")
})
</script>
<link href="styles/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<button onclick="topFunction()" id="myBtn" title="Go to top">Back to Top</button>
<script src = "scripts/topnav.js"></script>
<script src = "scripts/topbutton.js"></script>
<div id = "nav-placeholder"></div>
<header>
<nav class = "topnav" id = "myTopnav">
<h1 class = "logo">General Gaming Guides</h1>
<a href = "javascript:void(0);" class = "icon" onclick = "myFunction()">
<i class = "fa fa-bars"></i>
</a>
</nav>
</header>
<div class = "middle_text">
Text here.
</div>
</body>
</html>
And my navigation bar page called nav.html code is here:
<div>
<ul class = "mainnav">
<li><a href = "index.html">Home</a></li>
<li><a href = "games.html">Games</a>
<ul class = "gamesnav">
<li><a href = "lostark.html">Lost Ark</a>
<ul class = "subnav">
<li><a href = "news.html">News</a></li>
<li><a href = "patch_notes.html">Patch Notes</a></li>
<li><a href = "beginner_guide.html">Beginner's Guide</a>
<ul class = "subnav2">
<li><a href = "character_info.html">Understanding Game Design</a></li>
<li><a href = "road_to_50.html">Road to Level 50</a></li>
</ul>
</li>
<li><a href = "dailies.html">Dailies</a></li>
<li><a href = "weeklies.html">Weeklies</a></li>
<li><a href = "current-events.html">Current Events</a></li>
<li><a href = "abyssaldungeons.html">Abyssal Dungeons</a></li>
<li><a href = "legionraids.html">Legion Raids</a>
<ul class = "subnav2">
<li><a href = "valtan-gate-1-guide.html">Normal Mode</a></li>
<li><a href="valtan-hell-gate-1.html">Inferno/Extreme Mode</a></li>
</ul>
</li>
<li><a href = "kazerosraids.html">Kazeros Raids</a></li>
<li><a href = "adventure_islands.html">Adventure Islands</a></li>
</ul>
</li>
</ul>
</li>
<li><a href = "about.html">About</a></li>
<li><a href = "support.html">Support</a></li>
</ul>
</div>
Any help to get it to show would be appreciated!