IntersectionObserver: unobserve() method
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("Intersection Observer API")}}
The **unobserve()** method of the {{domxref("IntersectionObserver")}} interface instructs the IntersectionObserver to stop observing the specified target element.
Syntax
js-nolint
unobserve(target)Parameters
target- : The {{domxref("Element")}} to cease observing.
If the specified element isn't being observed, this method does nothing and no exception is thrown.
Return value
None ({{jsxref("undefined")}}).
Examples
This snippet shows an observer being created, an element being observed, and then being unobserved.
js
const observer = new IntersectionObserver(callback);
observer.observe(document.getElementById("elementToObserve"));
// …
observer.unobserve(document.getElementById("elementToObserve"));Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- Intersection Observer API
- {{domxref("IntersectionObserver.observe()")}}