I have been facing an error in following code star marked option but it was executed the last run of my project but actually today it shows "Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'." on the browser.
const counters = document.querySelectorAll(".counter");
function playCounter() {
counters.forEach((counter) => {
counter.innerText = 0;
let point = +counter.dataset.count;
let step = point / 100;
let startCount = function () {
let displayCount = +counter.innerText;
if (displayCount < point) {
counter.innerText = Math.ceil(displayCount + step);
setTimeout(startCount, 500);
} else {
counter.innerText = point;
}
};
startCount();
});
}
let counterSection = document.querySelector(".counter_wrapper");
let scope = {
borderMargin: "0px 0px -200px 0px",
};
const sectionObserver = new IntersectionObserver(function (entry) {
if (entry[0].isIntersecting) {
playCounter();
}
}, scope);
**sectionObserver.observe(counterSection);**