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

244
Views
Smooth scroll polyfill not working inside a forEach loop

I'm using the smooth scroll polyfill npm package https://github.com/iamdustan/smoothscroll on a website I'm developing and despite trying for hours, I can't get it working. After importing and invoking the package I'm calling a function that adds an event listener to all links with a data attribute of "navigate-to" so that the appropriate element would be scrolled into view. Does anyone have any ideas what could be causing the problem? I suspect it might have something to do with the addeventlistener being appliead inside a forEach? Thanks in advance!

    import smoothscroll from "smoothscroll-polyfill";
    smoothscroll.polyfill();

    function anchorScrollTo() {
     document.querySelectorAll("[data-navigateTo]").forEach(function (e) {
     e.addEventListener("click", function (event) {
      document.querySelector(e.dataset.navigateto).scrollIntoView({ behaviour: "smooth" });
    });
  });
}
     anchorScrollTo()
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After trying a few more solutions, I noticed that for some reason the polyfill doesn't work with querySelectorAll, so I just created an array of classes that I loop through and select each of the elements with querySelector instead.

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!