Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!