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

103
Views
targeting multiple elements with intersection observer API

I have an Intersection Observer working for an element on the page, however I want to now apply a completely different animation to another element on the page. I tried creating multiple observers, but it broke. I tried another stackOverflow post where I created an array and tried to use if statements, it broke. I'm still fairly new to JS and learning how to apply logic to different statements, and I'm just stuck not understanding why I can't target multiple elements?

    const backgroundTitles = document.querySelectorAll('.section-title span')
const artLoad = document.querySelector('.artwork')

const items = [backgroundTitles, artLoad]

const observer = new IntersectionObserver(entries => {
  entries.forEach(entry => {
    entry.target.classList.toggle('bgtitle', entry.isIntersecting)
  })
  console.log(entries)
})

const newObserver = new IntersectionObserver(entries2 => {
  entries2.forEach(entry => {
    entry.target.classList.toggle('openAnimation', entry.isIntersecting)
  })
})

backgroundTitles.forEach(title => {
  observer.observe(title)
})

// artLoad.forEach(art => {
//   newObserver.observe(art)
// })

I'm sure this is something simple and I'm just not getting it. When I apply the artLoad.forEach... I get an error that artLoad isn't a function? Not sure why.

about 4 years ago · Santiago Trujillo
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!