vendredi 2 juin 2017

go back to initial state when unclick checkbox

I have:

 <label><input type="checkbox" name="all"> text</label>
 <label><input type="checkbox" name="js-frameworks"> text</label>

const all = document.getElementsByName('all')[0];
const jsFrameworks = document.getElementsByName('js-frameworks')[0];

this.addEventListener("change", function() {
    if (all.checked) {
    jsFrameworks.parentNode.className = 'readonly';
    } 
});

I thought that when I deselect the checkbox the class 'readonly' will be removed as the code executes only when I tick the checkbox giving the if condition is true. I can't seem to escape the if condition, so to kind of toggle between the click and unclick. How can I do that?

Thanks

Aucun commentaire:

Enregistrer un commentaire