JavaScripture
Contribute via GitHub Feedback

MutationObserver : Object

MutationObserver allows you to provide a function that is called asynchronously when certain parts of the DOM change, such as adding a child to a node, changing an attribute on a node, or changing the text on a node. As the changes happen, the MutationObserver records them as MutationRecords and then calls a user provided callback at a later time with all the MutationRecords that are pending.

Constructors

new MutationObserver(callback : Function) : MutationObserver
callback(mutations : Array<MutationRecord>, observer : MutationObserver) : undefined

Creates a new MutationObserver that will call callback when the behaviors configured by observe() change. Note that callback will be called at some time after the current script that is doing the mutation completes. The observer passed to callback is the newly created MutationObserver.

Example:

Run

Results:

 

Instance Methods

disconnect() : undefined

Unhooks this observer from all targets specified in previous observe() calls.

observe(target : Node, options : Object) : undefined
options : {
childList :BooleanObserves changes to the children of target.
attributes :BooleanObserves changes to the attributes of target.
characterData :BooleanObserves changes to the data of target.
subtree :BooleanTells the observer to also record changes in the subtree of target
attributeOldValue :BooleanTells the observer to provide the old value of the attribute (available in the MutationRecord.oldValue property).
characterDataOldValue :BooleanTells the observer to provide the old value of the character data (available in the MutationRecord.oldValue property).
attributeFilter :Array<String>Tells the observer to only observe the specified attributes.
}

Registers the observer to be called any time the specified options on target change. If observe() is called more than once, it will listen to changes on each target. See MutationRecord for the data provided to callback for each mutation type.

Example:

Run

Results:

 

takeRecords() : Array<MutationRecord>

Returns the queued list of MutationRecords for this and clears out that list. The callback will not be called unless additional mutations occur after the call to takeRecords().

Example:

Run

Results: