Javascript Observe Element Mutation / Watch for DOM changes


var anObserver = new MutationObserver(function(mutationList, observer) {
    mutationList.forEach(function (mutation) { // attributes: false, childList: true, subtree: true
        if (mutation.type=='childList') {
            console.log("perubahan ");
            anObserver.disconnect();//stop observing
        }
    });
});
targetNode = document.querySelector("#targetid")
anObserver.observe(targetNode, {attributes: false, childList: true, subtree: true});