Created
March 21, 2012 20:30
-
-
Save wtfgimmeaname/2152570 to your computer and use it in GitHub Desktop.
Watch function on inputs
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
function watch(label, input) { | |
var update = function() { | |
label.classList.remove(!input.checked); | |
label.classList.add(input.checked); | |
}; | |
update(); | |
input.addEventListener("change", update, false); | |
} | |
var inputs = document.querySelectorAll("input[type=checkbox]"); | |
for (var i = 0; i < inputs.length; i++) { | |
for (var j = 0; j < inputs[i].labels.length; j++) { | |
watch(inputs[i].labels[j], inputs[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment