Mutation Observer is an interface for monitoring DOM changes. When there is any change in the DOM object tree, Mutation Observer will be notified. This article will share with you the undo and fallback operations of the editor based on the new HTML5 feature Mutation Observer. Interested friends will refer to the introduction of MutationObserver.
MutationObserver provides developers with the ability to respond appropriately when DOM trees within a certain range change. The API is designed to replace the Mutation events introduced in the DOM3 event specification.
Mutation Observer is an interface for monitoring DOM changes. Mutation Observer is notified when any changes occur in the DOM object tree.
Mutation Observer has the following features:•It will wait for all script tasks to complete before it will run, that is, it will use an asynchronous method.
•It encapsulates DOM change records into an array for processing, rather than individually processing DOM changes.
•It can observe all changes that occur on the DOM node, or observe a certain type of changes.
MDN information: MutationObserver
MutationObserver is a constructor, so when creating it, you must use new MutationObserver;
When instantiating MutationObserver, a callback function is required, which will be called when the specified DOM node (target node) changes.
When called, the observer object will pass two parameters to the function:
1: The first parameter is an array containing several MutationRecord objects;
2: The second parameter is the observer object itself.
For example:
Copy the code