I'm currently building a website and trying to get this issue to work.
I have my header in a separate HTML document which looks like this:
<div class="topnav" id="myTopnav">
<a href="Index.html" id="home"><i class="fa fa-fw fa-home"></i>Home</a>
<a href="Drinks.html" id="drinks"><i class="fa fa-fw fa-coffee"></i>Drinks</a>
</div>
Now on every page I load the header from this HTML:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#content').load("Header.html");
});
</script>
</head>
<header class="head">
<div id="content"></div>
</header>
Now I'm trying to add dynamically a class to the "a href"-Tag to make it active but this does not work. I tried to write another function in the "head"-Tag:
<script>
function addAct() {
var element = document.getElementById("#home");
element.classList.add(".active");
};
</script>
and call it manually in the "head"-Tag right after calling the loading function:
<script>addAct()</script>
This does not seem to work. I tried a lot of other solution but could not find anything that is working. Can someone help?
Thanks a lot!
#homeshould not have#simply writedocument.getElementById("home");a