Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda