Skip to content
Advertisement

How to enable/disable nested checkboxes using jQuery

JavaScript

I have this piece of code in my Laravel Blade File. I am using jquery (after 4 Years, so need a bit of help out here) to set the checkbox inputs under id #subModule as disabled. (This is working fine)

JavaScript

Now what I am trying to achieve is based on the checkbox inputs under id #module, the corresponding submodule checkbox should get enabled/disabled.

enter image description here

What I have done till now is this but it is still not working

JavaScript

});

Can anyone help me? Any help will be much appreciated.

Advertisement

Answer

You need to use class selector instead of id . Then , on click of module checkboxes use .closest("row").find(".subModule > input[type=checkbox]") to refer your submodule checkbox and then simply do attr("disabled", false) to remove disable.

Demo Code:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement