Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mutation observer js

const observer = new MutationObserver(list => {
    console.log('mutation list', list);
});
observer.observe(document.body, {
    attributes: true,
    childList: true,
    subtree: true
});
// perform any DOM change action in your page. e.g. show/hide/remove
Comment

javascript mutation observer

var fnCallback = function (mutations) {
    mutations.forEach(function (mutation) {
        alert(mutation.target.id, "added: " + mutation.addedNodes.length + " nodes");
        alert(mutation.target, "removed: " + mutation.removedNodes.length + " nodes");
    });
};

var observer = new MutationObserver(fnCallback),
        elTarget = document.querySelector("#divTarget"),
        objConfig = {
            childList: true,
            subtree : true,
            attributes: true, 
            characterData : true,
            attributeFilter : ['style', 'id'],
            attributeOldValue : true
        };

    observer.observe(elTarget, objConfig);
    
    
    
    
    
    
    
//below here is just the test code    
var btnUpdate = document.querySelector("#btnUpdate"),
    fnHandler = function () {
        elTarget.innerHTML = "<h2>New content</h2>";
    };
    
    btnUpdate.addEventListener("click", fnHandler, false);
Comment

How to write a mutation observer js

let mList = document.getElementById('myList'),
            options = {
                childList: true,
                attributes: true,
                subtree: true
            },
            observer = new MutationObserver(mCallback);

        function mCallback(mutations) {
            for (let mutation of mutations) {
                // If you remove a child from the container you are watching
                if (mutation.type === 'childList') {
                    console.log('Mutation Detected: A child node has been added or removed.');
                }
                // If you use setAttribute to add a class or ID to an element
                if (mutation.type === 'attributes') {
                    console.log('Mutation Detected: An attribute has been added or removed.');
                }

                if (mutation.type === 'subtree') {
                    console.log('Mutation Detected: A subtree has been added or removed.');
                }
            }
        }

observer.observe(mList, options);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to refrence schema in my mongoose schema 
Javascript :: swap first and last element in array javascript 
Javascript :: javascript get last emlement array 
Javascript :: function syntax js 
Javascript :: LEAODE MAJE 
Javascript :: module parse failed: unexpected character ' (1:0) you may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. see https://webpack.js.org/concepts#loaders 
Javascript :: json stringify empties the array in js 
Javascript :: find longest word in a string javascript 
Javascript :: what would (int) (Math.random()) output 
Javascript :: can you get reinfected with the coronavirus 
Javascript :: patterns in javascript using for loop 
Javascript :: var s= 
Javascript :: vuejs cordoba pantalla en blanco 
Javascript :: js no new line console.log 
Python :: python request remove warning 
Python :: jupyter display all columns 
Python :: how to change django admin text 
Python :: open firefox python 
Python :: how many nan in array python 
Python :: torch device 
Python :: pandas create empty dataframe 
Python :: how to install pyaudio in python 
Python :: clear_output jupyter 
Python :: python get line number of error 
Python :: for loop django template count 
Python :: python read file to variable 
Python :: find common elements in two lists python 
Python :: change specific column name pandas 
Python :: pytorch summary model 
Python :: shapely polygon from string 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =