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

118
Vistas
How to scroll to a certain section in a page without using href attribute

My navigation bar is self populated with javascript.

function liCreation() {
   for(noOfSection of noOfsections) {
       sectionAddress = noOfSection.getAttribute('data-nav');
       section =noOfSection.getAttribute('id');
       liTag = document.createElement('li');
       liTag.innerHTML = `<a class='menu__link'>${sectionAddress}</a>`;
}
}

So it comes out with a navigation bar menu that has 4 sections (because I got 4 sections in my page) I want to scroll to a section without adding href="${section}" to the anchor element.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Why? It gives several benefits. Href shows the arrow pointer and no code is needed to scroll

If you must, then

document.querySelector("ul.nav").addEventListener("click", function(e) {
   const tgt = e.target;
   if (tgt.tagname === "A" && tgt.classList.contains("menu__link")) {
      document.getElementById(tgt.textContent.trim()).scrollIntoView();
   }
})

assuming the id is in the text of the anchor and the ul containing the LIs have a class of .nav

about 4 years ago · Juan Pablo Isaza Denunciar
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