Skip to content

Instantly share code, notes, and snippets.

@wtfgimmeaname
Created March 21, 2012 20:30
Show Gist options
  • Save wtfgimmeaname/2152570 to your computer and use it in GitHub Desktop.
Save wtfgimmeaname/2152570 to your computer and use it in GitHub Desktop.
Watch function on inputs
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