I have written code that toggles the display of a home page element from an option in the nav bar which works. However I would also like this code to execute on load when the same option is selected to navigate back to my home page and display element.
Currently it navigates to the home page but does not apply the display changes to show element on load and nav bar option has to be clicked again to display element.
this is my code
abNav = () => {
abLoad = () => {
about.style.display = "block";
design.style.display = "none";
program.style.display = "none";
project.style.display = "none";
contact.style.display = "none";
}
if (
window.location.href === "./index.html#home"
){
window.onload = abLoad();
} else {
return abLoad();
}
}
HTML Nav bar option with onclick function
<li>
<a href="#home" id="about-nav" onclick="abNav()">About</a>
</li>