CKTIS / JavaScript
IntersectionObserver.disconnect(): stopping observation
disconnect() stops an IntersectionObserver from observing all its targets while allowing the observer to be reused.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
observer.disconnect()observer.disconnect() removes all targets from that observer. It takes no arguments and returns undefined. Unlike unobserve(target), it is not limited to one element. Repeated calls are safe; a later observe(target) starts observation again.
The method does not empty existing queued records, so an already queued notification may still invoke the callback. To retrieve and empty pending records, use takeRecords(); process its result or deliberately discard it. Call disconnect() during component cleanup. This is a Web API, not a feature of a particular ECMAScript edition; check IntersectionObserver availability in the target browser.
Examples
(() => {
const targets = [document.createElement('div'), document.createElement('div')];
const observer = new IntersectionObserver(() => {});
targets.forEach(target => observer.observe(target));
console.log(observer.disconnect() === undefined);
observer.disconnect();
console.log(observer.takeRecords().length);
observer.observe(targets[0]);
observer.disconnect();
})();Result
true 0
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.