Skip to content

Instantly share code, notes, and snippets.

@Rockncoder
Created February 13, 2013 16:50
Show Gist options
  • Save Rockncoder/4946017 to your computer and use it in GitHub Desktop.
Save Rockncoder/4946017 to your computer and use it in GitHub Desktop.
A demo of Live DOM Objects
<h1>Live DOM Objects</h1>
<button onclick="runTest()">Run Test</button>
<div>#1</div>
<div>#2</div>
<script type="text/javascript">
function runTest() {
var div, ndx, divs = document.getElementsByTagName("div");
/*
This despite appearances is an endless loop
Execute with caution
*/
debugger;
for(ndx=0; ndx < divs.length; ndx++){
div = document.createElement("div");
/* every time we add a div to the page, divs.length increases */
document.body.appendChild(div);
debugger;
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment