<div>
<check-to-toggle target="#foo">
<div class="form-check">
<label class="form-check__label">
<input type="checkbox" class="form-check__input check-to-toggle__checkbox" />
Toggle
</label>
</div>
</check-to-toggle>
<div id="foo">I can be toggled</div>
</div>
<div>
<check-to-toggle target="#foo">
<div class="form-check">
<label class="form-check__label">
<input type="checkbox" class="form-check__input check-to-toggle__checkbox" />
Toggle
</label>
</div>
</check-to-toggle>
<div id="foo">I can be toggled</div>
</div>
/* No context defined. */
export default class CheckToToggle extends HTMLElement {
connectedCallback() {
this.checkbox.onclick = this.toggle.bind(this)
}
get checkbox() {
return this.querySelector('input[type="checkbox"]')
}
get target() {
const selector = this.getAttribute('target')
return document.querySelector(selector)
}
toggle() {
this.target.classList.toggle('is-hidden')
}
}
No notes defined.