jeudi 9 mai 2019

How to disable grouped checkboxes while keeping the clicked one enable?

I have a group of check boxes with same class name, I want to disable the rest when one is clicked and keep the clicked one enable. I have tried the solution here: disable other checkboxes when one with similar class is clicked

However the solution does not work for me and I can't figure out why.

HTML

<label><input type="checkbox" name="js-frameworks" class="group"> JavaScript Frameworks Workshop — Tuesday 9am-12pm, $100</label>
<label><input type="checkbox" name="express" class="group"> Express Workshop — Tuesday 9am-12pm, $100</label>

Script

$(".group").change(() => {
  console.log("hitting the check box");
  this.checked ? $("." + this.className).not(this).prop("disabled", true) : $("." + this.className).not(this).prop("disabled", false);
})

there is no error, and I hit the console.log every time i click but nothing happens. I have tried both change() and click() with no luck.




Aucun commentaire:

Enregistrer un commentaire