MutationObserver theo dõi thay đổi trên DOM tree (attribute changes, child additions/removals, text changes).
Asynchronous, callbacks chạy như microtask.
javascript
const observer = new MutationObserver(mutations => {
mutations.forEach(m => console.log(m.type, m.target));
});
observer.observe(document.body, { childList: true, subtree: true });
// observer.disconnect() để dừngHữu ích khi làm việc với third-party code thay đổi DOM, implement undo/redo, hay real-time updates.
ResizeObserver theo dõi thay đổi kích thước element.