Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
MutationObserver
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>MutationObserver</title>
<script src="dom_observer.js"></script>
</head>
<body>
<input type="button" value="Hello" onclick="appendTextNode()"/>
<div id="text-container"></div>
</body>
</html>
var target;
window.onload = function() {
target = document.getElementById('text-container');
var observer = new MutationObserver(function() {
alert('Mutation!');
});
observer.observe(target, { childList: true });
};
var appendTextNode = function() {
let textNode = document.createTextNode('World');
target.appendChild(textNode);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment