Back to Content

IntersectionObserver: unobserve() method

files/en-us/web/api/intersectionobserver/unobserve/index.md

latest1021 B
Original Source

{{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