MutationObserver provides developers a way to react to changes in a DOM. It is designed as a replacement for Mutation Events defined in the DOM3 Events specification.
let observerOptions = {
childList: true,
attributes: true,
characterData: false,
subtree: false,
attributeFilter: ['one', 'two'],
attributeOldValue: false,
characterDataOldValue: false
};
const targetNode = document.getElementById('myId');
let observer = new MutationObserver(callback);
function callback (mutations) {
// do something here
}
observer.observe(targetNode, observerOptions);