1
Fork 0

Force checkboxes to initial value

This commit is contained in:
Jake Howard 2024-09-02 22:07:05 +01:00
parent 545193a779
commit 4c77ecfc87
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 12 additions and 1 deletions

View file

@ -6,12 +6,13 @@
<p>Here's some content before</p>
<div class="code-collapse-wrapper">
<input type="checkbox" id="collapse" />
<input type="checkbox" id="collapse" checked />
<label class="open-tag" for="collapse" aria-label="tag">&lt;tag</label>
<div class="collapse-content">This is the inner content</div>
<label for="collapse" class="close-tag">&lt;/tag&gt;</label>
</div>
<p>Text below the collapse, which should move out the way</p>
<script type="module" src="index.js"></script>
</body>
</html>

View file

@ -0,0 +1,10 @@
const collapse = document.getElementById("collapse");
document.addEventListener("DOMContentLoaded", function () {
// Force checkboxes to their initial value
for (const checkbox of this.document.querySelectorAll(
"input[type=checkbox",
)) {
checkbox.checked = checkbox.defaultChecked;
}
});