Skip to content

Instantly share code, notes, and snippets.

@brianmcd
Created September 7, 2012 22:22
Show Gist options
  • Save brianmcd/3670240 to your computer and use it in GitHub Desktop.
Save brianmcd/3670240 to your computer and use it in GitHub Desktop.
<html>
<body>
<label for="box1">With default:</label><input type="checkbox" checked="" id="box1">
<label for="box2">Prevent default:</label><input type="checkbox" checked="" id="box2">
<script>
var box1 = document.getElementById('box1');
var box2 = document.getElementById('box2');
[box1, box2].forEach(function (box) {
box.addEventListener('click', function (e) {
console.log("The value of checked is:", box.getAttribute("checked"));
console.log("box.checked:", box.checked);
if (box === box2) {
e.preventDefault();
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment