DOM MutationObserver

Observe DOM mutations.

by Lucaskazama

HTML

<div id="some-id">
    <input type="button" value="Click" onclick="duplicate()" />
    <input id="fp-phone" class="amigoclass" type="text" value="" placeholder="teste" />
</div>

CSS

#some-id>div {
    width: 16px;
    height: 16px;
    background: red;
    margin: 3px;
}

JavaScript

var target = document.querySelector('.amigoclass');

// create an observer instance
var observer = new MutationObserver(function (mutations) {
    mutations.forEach(function (mutation) {        
        if(mutation.target.placeholder){
        	console.log(mutation.target.placeholder);
        } else{
        	console.log('Fraude')
        }
    });
});

// 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);


function duplicate() {
    target.setAttribute('placeholder', 'amigao')
}