Last active
August 29, 2015 14:06
-
-
Save cjwainwright/524a2bb306ed9175c6c0 to your computer and use it in GitHub Desktop.
Demonstrates how innerHTML can destroy the DOM structure of the original child nodes it replaces in IE9
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> | |
<body> | |
<div id="a"> | |
<div id="b"> | |
<div id="c">Original Child 1</div> | |
<div>Original Child 2</div> | |
</div> | |
</div> | |
<script type="text/javascript"> | |
// get references to a couple of child nodes | |
var b = document.getElementById('b'); | |
var c = document.getElementById('c'); | |
// replace all children by updating the innerHTML | |
document.getElementById('a').innerHTML = '<div>Replacement</div>'; | |
// check the structure of the original child nodes | |
console.log(b.childNodes.length); // expect > 0, is 0 in IE9 | |
console.log(c.innerHTML); // expect "Original Child 1", is "" in IE9 | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment