Force checkboxes to initial value
This commit is contained in:
parent
545193a779
commit
4c77ecfc87
2 changed files with 12 additions and 1 deletions
|
@ -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"><tag</label>
|
||||
<div class="collapse-content">This is the inner content</div>
|
||||
<label for="collapse" class="close-tag"></tag></label>
|
||||
</div>
|
||||
|
||||
<p>Text below the collapse, which should move out the way</p>
|
||||
<script type="module" src="index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
10
src/code-collapse/index.js
Normal file
10
src/code-collapse/index.js
Normal 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;
|
||||
}
|
||||
});
|
Loading…
Reference in a new issue