Created
February 27, 2012 15:01
-
-
Save zentooo/1924408 to your computer and use it in GitHub Desktop.
NodeList and StaticNodeList
This file contains hidden or 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> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<div class="a" onclick="this.parentNode.removeChild(this);">a - remove</div> | |
<div class="a" onclick="this.parentNode.appendChild(this.cloneNode(true));">a - clone</div> | |
<div class="a" onclick="this.appendChild(this.cloneNode(true));">a - appendChild</div> | |
<div class="b" onclick="this.parentNode.removeChild(this);">b - remove</div> | |
<div class="b" onclick="this.parentNode.appendChild(this.cloneNode(true));">b - clone</div> | |
<div class="b" onclick="this.appendChild(this.cloneNode(true));">b - appendChild</div> | |
<div class="c" onclick="this.parentNode.removeChild(this);">c - remove</div> | |
<div class="c" onclick="this.parentNode.appendChild(this.cloneNode(true));">c - clone</div> | |
<div class="c" onclick="this.appendChild(this.cloneNode(true));">c - appendChild</div> | |
<div class="d" onclick="this.parentNode.removeChild(this);">d - remove</div> | |
<div class="d" onclick="this.parentNode.appendChild(this.cloneNode(true));">d - clone</div> | |
<div class="d" onclick="this.appendChild(this.cloneNode(true));">d - appendChild</div> | |
<button id="a-button"> | |
a | |
</button> | |
<button id="b-button"> | |
b | |
</button> | |
<button id="c-button"> | |
c | |
</button> | |
<button id="d-button"> | |
d | |
</button> | |
<script type="text/javascript"> | |
document.addEventListener("DOMContentLoaded", function() { | |
var elems = {}; | |
elems["a"] = document.getElementsByClassName("a"); | |
elems["b"] = Array.prototype.slice.call(document.getElementsByClassName("b")); | |
elems["c"] = document.querySelectorAll(".c"); | |
elems["d"] = Array.prototype.slice.call(document.querySelectorAll(".d")); | |
Object.keys(elems).forEach(function(key) { | |
document.getElementById(key + "-button").addEventListener("click", function() { | |
for ( var i = 0, iz = elems[key].length; i < iz; i++ ) { | |
console.log(elems[key][i].innerHTML); | |
} | |
}, false); | |
}); | |
}, false); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment