Skip to content

Instantly share code, notes, and snippets.

@cjwainwright
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjwainwright/524a2bb306ed9175c6c0 to your computer and use it in GitHub Desktop.
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
<!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