back to catalog
MutationObserver vs timer

    const dom = document.getElementById('container')

    var config = { attributes: true, childList: true, subtree: true };

    var callback = function(mutationsList, observer) {
        for(var mutation of mutationsList) {
            if (mutation.type == 'childList') {
                console.log('MutationObserver event callback')
            }
            else if (mutation.type == 'attributes') {
                console.log('The ' + mutation.attributeName + ' attribute was modified.');
            }
        }
    };

    var observer = new MutationObserver(callback);

    observer.observe(dom, config);

    setTimeout(() => {
      console.log('setTimeout callback')
    })
    console.log('before trigger MutationObserver')
    const span = document.createElement('span')
    span.textContent = 'hello'
    dom.appendChild(span)
      
    setTimeout(() => {
      console.log('disconnect')
      observer.disconnect();
    }, 3000)