Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

57
Views
JS - modify dom element to display onload when navigating from a page nav bar option using onclick function

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>
7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.