Answers for "Uncaught TypeError: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'"

0

Uncaught TypeError: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'

============ READ CAREFULLY then you will understand ========================
Whatever your code may look like, this are some solutions you could do:

1. Make sure the DOM Content ist loaded with an event like this:
document.addEventListener('DOMContentLoaded', (event) => {
  // Your Code here
});

2. If you are trying to observe more than one Element do a foreach like this:
const io = new IntersectionObserver(entries => {
  entries.forEach(entry => {
    // Your code here, for example adding and removing classes
    }
});
	// Query selecting all the elements inside that container
const boxList = document.querySelectorAll('.boxContainer .boxes');
boxList.forEach((element) => {
  // Here you will notice we call the observe() method on each element
  io.observe(element);
})

3. Use querySelector for only one element you want to observe:
const myDiv = document.querySelector('.mySmolDiv');
  
HOPE IT WORED :)
Posted by: Guest on October-18-2021

Code answers related to "Uncaught TypeError: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'"

Code answers related to "Javascript"

Browse Popular Code Answers by Language