Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7653285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:59:34+00:00 2026-05-31T11:59:34+00:00

I am using multiple checkbox with hierarchy ..i have parent checkbox and its child

  • 0

I am using multiple checkbox with hierarchy ..i have parent checkbox and its child checkbox … up to 3 4 level.. i am using this code it is working fine for me … but i want to reduce my code..

any one please tell me..

<script type="text/javascript">
    jQuery(document).ready(function(){

        jQuery('input[type=checkbox]').change(function() {
            var id = jQuery(this).attr('id');
            var children = jQuery('.parent-' + id).attr('checked', jQuery(this).attr('checked'));
        });

        jQuery("input[class^='parent-']").click(function(){
            if(jQuery(this).attr('checked')){
                var id = jQuery(this).attr('class');
                var parts = id.split('-');
                var parent_node = jQuery('.lead-' + parts[1]).attr('checked', jQuery(this).attr('checked'));
            }else{
                var id = jQuery(this).attr('class');
                var parts = id.split('-');
                if(jQuery(".parent-"+ parts[1]+":checked").length==0)
                {
                    var parts = id.split('-');
                    var parent_node = jQuery('.lead-' + parts[1]).removeAttr('checked', jQuery(this).attr('checked'));
                }
            }
        });

        jQuery("input[class^='parent-']").each(function(){
            if(jQuery(this).attr('checked')){
                var id = jQuery(this).attr('class');
                var parts = id.split('-');
                var parent_node = jQuery('.lead-' + parts[1]).attr('checked', jQuery(this).attr('checked'));
            }else{
                var id = jQuery(this).attr('class');
                var parts = id.split('-');
                if(jQuery(".parent-"+ parts[1]+":checked").length==0)
                {
                    var parts = id.split('-');
                    var parent_node = jQuery('.lead-' + parts[1]).removeAttr('checked', jQuery(this).attr('checked'));
                }
            }
        });

    });
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:59:35+00:00Added an answer on May 31, 2026 at 11:59 am
    jQuery("input[class^='child-']").click(function(){
                var cls = jQuery(this).attr('class');
                parts = cls.split('-');
                var check = false;
                jQuery("input[type=checkbox]."+cls).each(function() {
                    if(jQuery(this).is(':checked')) {
                        jQuery("input[type=checkbox].parent-"+parts[1]).attr('checked', 'checked');
                        check = true;
                    }
                });
                if(!check) { jQuery("input[type=checkbox].parent-"+parts[1]).removeAttr('checked'); }
            });
    
            jQuery("input[class^='parent-']").click(function() {
                parts = jQuery(this).attr('class').split('-');
                if(jQuery(this).is(':checked')) {
                    jQuery("input[class$='"+parts[1]+"']").attr('checked', 'checked');
                } else {
                    jQuery("input[class$='"+parts[1]+"']").removeAttr('checked');
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code to check if the checkbox is checked or not..
I have dynamic page. There are multiple checkboxes & I am using this script
I am using this code to try and submit a value via form but
I want to save the state of a multiple choice listview checkbox's. I have
I have a user control that contains multiple controls (CheckBox, Button, Label...). I want
Does using Multiple .NET Languages (Delphi, VB.NET, C#) into the same application (but in
I'm using multiple threads in my application. Basically I have a combo box and
This is my first major application using multiple classes. It is written in vb
I want to update a single datarow in a datatable using multiple threads. Is
I have been following the following post on using multiple ItemTemplates in a ListView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.