2020-09-11 13:37:18 -03:00
|
|
|
<html>
|
2021-04-04 12:49:22 -03:00
|
|
|
<input id=foo type=checkbox>
|
2022-02-16 11:55:13 -03:00
|
|
|
<label for=foo>Checkbox 1 (with a "for" attribute)</label>
|
|
|
|
|
<pre id=foo-status></pre>
|
|
|
|
|
|
|
|
|
|
<label>
|
|
|
|
|
<input id=bar type=checkbox>
|
|
|
|
|
Checkbox 2 (inside a label element)
|
|
|
|
|
</label>
|
|
|
|
|
<pre id=bar-status></pre>
|
|
|
|
|
|
2020-09-11 13:37:18 -03:00
|
|
|
<script>
|
|
|
|
|
var foo = document.getElementById("foo");
|
2022-02-16 11:55:13 -03:00
|
|
|
var fooStatus = document.getElementById("foo-status");
|
|
|
|
|
fooStatus.innerHTML = `Checkbox 1: ${foo.checked}\n`;
|
|
|
|
|
|
2020-09-11 13:37:18 -03:00
|
|
|
var bar = document.getElementById("bar");
|
2022-02-16 11:55:13 -03:00
|
|
|
var barStatus = document.getElementById("bar-status");
|
|
|
|
|
barStatus.innerHTML = `Checkbox 2: ${bar.checked}\n`;
|
|
|
|
|
|
2020-09-11 13:37:18 -03:00
|
|
|
foo.addEventListener("change", function() {
|
2022-02-16 11:55:13 -03:00
|
|
|
fooStatus.innerHTML = `Checkbox 1: ${foo.checked}\n`;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
bar.addEventListener("change", function() {
|
|
|
|
|
barStatus.innerHTML = `Checkbox 2: ${bar.checked}\n`;
|
2020-09-11 13:37:18 -03:00
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
</html>
|