I have a checkbox inside a label. I added the event listener for the click event to the label, so as to trigger the class.
It does work when I click the checkbox.
However, if I click the label, nothing changes. Why is that, considering that the event is binded to the label and not the checkbox?
const formCheck = document.querySelector('.drinos-checker')
formCheck.addEventListener('click', function () {
formCheck.classList.toggle('checkerActive')
})
.checkerActive {
background-color: red;
}
<label class="drinos-checker"><input class="drinos-checkbox" type="checkbox" name="checkbox" value="value">Renovation</label>