MutationObserver接口


MuataionObserver 替代了 MutationEvent
当被监听的节点发生变化时,执行某段函数

btn.onclick = function() {
  document.body.removeChild(document.getElementById('test'))
}

let observer = new MutationObserver(() => {
    console.log(4);
});
observer.observe(document.body, {
    attributes: false,  //节点属性如class等改变是否触发
    childList: true  //子节点改变
    characterData: false //
});