Last active
August 29, 2015 14:15
-
-
Save KitaitiMakoto/fefb4a082a0af01a92ac to your computer and use it in GitHub Desktop.
labelのforの対象は後から追加されても有効 ref: http://qiita.com/KitaitiMakoto/items/ac8bc9cdd62a8f6c37bd
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> | |
<button onclick="removeInput()">Remove input</button> | |
<button onclick="insertInput()">Insert input</button> | |
<label for="input">label</label> | |
<input id="input"> | |
<script> | |
inputs = document.getElementsByTagName("input"); | |
function removeInput() { | |
console.info(inputs.length, inputs); | |
for (var l = inputs.length, i = l - 1; i >= 0; i--) { | |
var input = inputs[i]; | |
input.parentNode.removeChild(input); | |
} | |
} | |
function insertInput() { | |
console.info(inputs); | |
var input = document.createElement("input"); | |
input.id = "input"; | |
document.body.appendChild(input); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment