1. 程式人生 > >dom元素改變監聽

dom元素改變監聽

dom元素 options cal change bsp each fun 監聽 pass

 function domChange(domId, callback) {
            // select the target node
            var target = document.getElementById(domId);
            // create an observer instance
            var observer = new MutationObserver(function (mutations) {
                mutations.forEach(function (mutation) {
                    callback();
                });
            });
            
// configuration of the observer: var config = { attributes: true, childList: true, characterData: true }; // pass in the target node, as well as the observer options observer.observe(target, config); // later, you can stop observing //observer.disconnect();
}

dom元素改變監聽