-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
26 lines (21 loc) · 908 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var container = document.getElementById("container");
var addNode = function() {
var div = document.createElement("div");
div.innerHTML = "<h1 title='The header'><span>Added node</span></h1>";
container.appendChild(div);
};
var removeNode = function() {
if (!container.hasChildNodes()) {
alert("There is no node...");
return;
}
container.removeChild(container.firstChild);
};
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.type + ". New: " + mutation.target.textContent + ". Old: " + mutation.oldValue);
});
});
var config = { attributes: true, childList: true, characterData: true, attributeOldValue : true, characterDataOldValue: true };
observer.observe(container, config);