1)はじめに DOMの監視をしたい、そんな時に使いやすいWebAPIがMutationObserverです。 今回はその利用方法について模索してみます。 2)MutationObserverとは その名の通り「Mutation(変化)」を「Observe(監視)」するAPI。 任意の要素(DOM)の変化を監視することが出来ます。 // 対象とするノードを取得 const target = document.getElementById('target'); // オブザーバインスタンスを作成 const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { // 何かしたいこと console.log(mutation.target); }); }); // オブザーバの設定 c