Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
How do I create a .js file that creates a navigation bar in html?

Ok I'm building this site and I want each page to have a nav bar, how do I make it so instead of having to write the html for the nav bar on each page I just write in the .js file and add this file javascript to each page.

By the way, I'm not asking how to write a navbar in html, I already did.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can use .insertAdjacentHTML and pass the 'afterbegin' as the "where" to add the html file. In this example, it is added as the first element of the body.

 const header= "<div>This is my nav</div>" document.querySelector("body").insertAdjacentHTML("afterbegin", header);
 <body> <div> Content of page <div> </body>
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda