CKTIS / JavaScript
ResizeObserver.unobserve() — stop observing one element
The unobserve(target) method removes one element from a ResizeObserver's observations while leaving its other targets unchanged.
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.unobserve(target)observer.unobserve(target) removes the specified Element from this observer's target list. It returns undefined. Pass the element itself, not a selector string.
Calling it again for an unobserved element does nothing. In contrast, disconnect() removes all targets. Observation can resume through observe(target).
The method neither removes the element from the document nor retracts entries already passed to the callback. It is useful when cleaning up an individual component.
This is a browser API specified in Resize Observer Module Level 1, not an ECMAScript feature. Having Node 24 does not establish browser availability; check the target environment.
Examples
(() => {
const a = document.createElement('div');
const b = document.createElement('div');
for (const element of [a, b]) {
element.style.cssText = 'display:block;width:100px;height:20px';
document.body.append(element);
}
const observer = new ResizeObserver((entries) => {
console.log(entries.length === 1 && entries[0].target === b);
observer.disconnect();
a.remove();
b.remove();
});
observer.observe(a);
observer.observe(b);
observer.unobserve(a);
observer.unobserve(a);
})();Result
true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.