Last active
March 30, 2017 09:19
-
-
Save helloGoGo/ace65c199df0cfaf46eb7ffea6f0ce2c to your computer and use it in GitHub Desktop.
MutationObserver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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