How to enable or disable nested checkboxes in jQuery ? Last Updated : 10 Dec, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will see how to enable or disable nested checkboxes in jQuery. To do that, we select all child checkboxes and add disabled attributes to them with the help of the attr() method in jQuery so that all checkboxes will be disabled. Syntax: // Select all child input of type checkbox // with class child-checkbox // And add the disabled attribute to them $('.child-checkbox input[type=checkbox]') .attr('disabled', true); After that, we add a click event listener to the parent checkbox, so when we click on the parent checkbox, if it is checked, all of its child checkboxes become enable. Else it's all child checkboxes become disable. Below is the implementation of this approach : Example: HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title> How to enable or disable nested checkboxes in jQuery? </title> <!-- Link of JQuery cdn --> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script> </head> <body> <div class="container"> <div class="parent-checkbox"> <input type="checkbox"> Govt. employe </div> <div class="child-checkbox"> <input type="checkbox"> ldc <input type="checkbox"> clerk <input type="checkbox"> watchmen </div> </div> <script> // Select child-checkbox classes all checkbox // And add disabled attributes to them $('.child-checkbox input[type=checkbox]'). attr('disabled', true); // When we check parent-checkbox then remove disabled // Attributes to its child checkboxes $(document).on('click', '.parent-checkbox input[type=checkbox]', function (event) { // If parent-checkbox is checked add // disabled attributes to its child if ($(this).is(":checked")) { $(this).closest(".container"). find(".child-checkbox > input[type=checkbox]"). attr("disabled", false); } else { // Else add disabled attrubutes to its // all child checkboxes $(this).closest(".container"). find(".child-checkbox > input[type=checkbox]"). attr("disabled", true); } }); </script> </body> </html> Output: When parent checkbox disable: When parent checkbox enable: Comment More infoAdvertise with us Next Article How to enable/disable a button using jQuery ? N nikhilchhipa9 Follow Improve Article Tags : Web Technologies JQuery jQuery-Questions Similar Reads How to disable or enable form submit button in jQuery? Enabling or disabling the form submit button based on a checkbox selection in jQuery. This ensures user compliance with terms and conditions before form submission. Syntax:$('#enabled').click(function () { if ($('#submit-button').is(':disabled')) { $('#submit-button').removeAttr('disabled'); } else 2 min read How to enable/disable a button using jQuery ? Enabling/disabling a button using jQuery involves altering its functionality to either accept user input or not. This is typically done by manipulating its 'disabled' property or attribute through jQuery methods like `.prop()` or .attr().To enable/disable a button using jQuery, you'll need a basic H 2 min read How to make a Disabled Checkbox using jQuery Mobile ? jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating a Disabled Checkbox using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=âstylesheetâ 1 min read jQuery UI Checkboxradio enable() Method jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. Whether you are building highly interactive web applications, or you just need to add a date picker to a form control, jQuery UI is a perfect choice. In this article 1 min read How to Disable a Button in jQuery UI ? To disable a button in jQuery UI, we will be using disable() method which is discussed below: jQuery UI disable() method is used to completely disable the button. It returns the button element completely to its initial state. Syntax: $(".selector").button("disable") Parameters: This method does not 2 min read How to hide the checkbox based on value in jQuery? The checkbox is used to set the content according to the user which he wants to see at the interface. Users also can set multiple choices according to their wishes.Syntax:$('input[name=foo]').attr('checked', false);ApproachIntegrate jQuery in HTML file via CDN Links. Includes the necessary title. Ad 2 min read Like