Skip to main content

observeElement

Callable

  • observeElement<T>(el: T, callback: (mutation: MutationRecord, observer: MutationObserver) => void, options?: MutationObserverInit): Disconnect

  • Observes changes to an element and invokes a callback function for each mutation.

    @example
    const disconnect = observeElement(document.body, (mutation, observer) => {
    console.log(mutation)
    })

    Type parameters

    • T: Element = Element

    Parameters

    • el: T

      The element to observe.

    • callback: (mutation: MutationRecord, observer: MutationObserver) => void

      The function to call when a mutation occurs.

    • optionaloptions: MutationObserverInit

      Optional configuration options for the MutationObserver.

    Returns Disconnect

    A function that disconnects the observer.