Rx.DOM.fromMutationObserver(target, options)

# [Ⓣ][1]

Creates an observable sequence from a MutationObserver. The MutationObserver provides developers a way to react to changes in a DOM. This requires MutationObserver to be supported in your browser/JavaScript runtime.

Arguments

  1. target (Node): The Node on which to obserave DOM mutations.
  2. options (MutationObserverInit): A MutationObserverInit object, specifies which DOM mutations should be reported.

Returns

(Observable): An observable sequence which contains mutations on the given DOM target.

Example

var foo = document.getElementById('foo');

var obs = Rx.DOM.fromMutationObserver(foo, { 
    attributes: true, 
    childList: true, 
    characterData: true,
    attributeFilter: ["id", "dir"]
});

foo.dir = 'rtl';

// Listen for mutations
obs.subscribe(function (mutations) {
    mutations.forEach(function(mutation) {
        console.log("Type of mutation: " + mutation.type);

        if ("attributes" === mutation.type) {
            console.log("Old attribute value: " + mutationRecord.oldValue);
        }
    });
});