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

208
Views
My JS code doesn't execute when I scroll down

The main problem is when I scroll down with the mouse my vanilla JS code doesn't execute because forEach is not a function. I don't know why this happens, I hope you can help me with this issue, thanks!

const boxes = document.querySelector(".box");

// event listener on scroll
window.addEventListener("scroll", animateDiv);
// visible content on load
animateDiv();

function animateDiv() {
    const animateTrigger = (window.innerHeight / 5) * 4;

    boxes.forEach((box) => {
        // height of div from in comparison to scroll
        const divTop = box.getBoundingClientRect().top;

        if (divTop < animateTrigger) {
            box.classList.add("show");
        } else {
            box.classList.remove("show");
        }
    });
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you need to use this

https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll

And not querySelector

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!