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

395
Views
intersection oberserver used with a loop through all the elements ends in error

I want to show some cards on scroll and for that purpose I chose to use an intersection observer. But I ended up with:
Uncaught TypeError: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'.
Here is a sample code of what I am trying to do =>

HTML:

<div class="card">demo</div>
<div class="card">demo</div>
<div class="card">demo</div>
<div class="card">demo</div>

JS:

const cards = document.querySelectorAll(".card");

const options = {
    root: null,
    threshold: 0.2
}

const observer = new IntersectionObserver(function(entries, observer) {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            entry.target.classList.add("appear-on-scroll");
            observer.unobserve(entry.target);
        } else {
            return;
        }
    });
}, options);
observer.observe(cards);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The answer is to loop through the array that consists of nodes twice like:

const cards = document.querySelectorAll(".card");

const options = {
    root: null,
    threshold: 0.2
}

const observer = new IntersectionObserver(function(entries, observer) {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            entry.target.classList.add("appear-on-scroll");
            observer.unobserve(entry.target);
        } else {
            return;
        }
    });
}, options);

// second loop through
cards.forEach(card => observer.observe(card));
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!