I have one script 'script.js' set up to assign active class to an li tag based on the url.
window.onload = function () {
jQuery(document).ready(function ($) {
// Get current path and find target link
var path = window.location.pathname.split("/").pop();
// Account for home page with empty path
if (path == '') {
path = 'HomePage.html';
}
var target = $('nav a[href="' + path + '"]');
// Add active class to target link
target.addClass('active');
});
Second script called 'JavaScript.js' this adds in the html of my shared menu bar from a separate html file:
window.onload = function () {var xmlhttp; var oe = document.getElementById("nav");xmlhttp = new XMLHttpRequest();xmlhttp.open("GET", "SharedMenu.html", false);xmlhttp.send();oe.innerHTML = xmlhttp.responseText;};
How do I make them work together in this format:
<!DOCTYPE html>
<html>
<head>
<title>jQuery Active Class</title>
<link href="style.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="script.js"></script>
<script src="JavaScript.js"></script>
</head>
<body>
<nav id="nav">
</nav>
<h1>contact</h1>
</body>
</html>