For example, I have a P element, inside is some text, and then I have a button, click the button to replace the contents of the P element, then the P element binding what event can let it tell me that it has been modified, what is the implementation method?
Reply content:
For example, I have a P element, inside is some text, and then I have a button, click the button to replace the contents of the P element, then the P element binding what event can let it tell me that it has been modified, what is the implementation method?
Http://stackoverflow.com/questions/9470931/is-there-any-on-dom-change-event
The newest mutationobserver should be able to meet the needs, see Https://developer.mozilla.org/zh-CN/docs/Web/API/MutationObserver
Mutationobserver provides developers with the ability to respond appropriately when a DOM tree changes in a range.
Covers child node changes, attribute changes.
If you use event listeners, such as domnodeinserted, domnoderemoved, and so on are more intuitive. But Mutationobserver was designed to replace Mutation events-domnodeinserted and so on.
This design is a bit like Promise, without the shadow of the event listener.
Thank you for inviting me. Click on the event where you send a ajax
request to send your modified action to someone else.
P element itself has no change
events, so you have to click on the button to do logic processing, anyway, click on this button will modify the P element content, the bad thing is that if more than one place is the modification of P, this time will be repeated to write the same logic processing, but if you use the framework, For example, angular and Vue offer such watcher.
DOMSubtreeModified
This event is seldom used by people ....