1

I'm trying to keep either All and a group of checkboxes (1, 2, 3) unchecked. For example, when All is unchecked and 1 is checked, if I click All, 1 should be unchecked, and vice versa.

<input type="checkbox" name="checkAll" class="selectAll" />  All  <br/>
<input type="checkbox" name="checkuser" class="cb_box "  />  1
<input type="checkbox" name="checkuser" class="cb_box "  />  2
<input type="checkbox" name="checkuser" class="cb_box "  />  3

I tried in this way but it doesn't work. Any suggestion?

$(function () {
 $('.selectAll').click(function () {
   $('input[name=checkuser]').attr('unchecked', $(this).attr('checked'));
});

2 Answers 2

2

Use this approach

Function prop along with event change

$('input[name="checkuser"]').prop('checked', $(this).is(':checked'));

$(function() {
    $('.selectAll').change(function() {
      $('input[name="checkuser"]').prop('checked', $(this).is(':checked'));
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="checkAll" class="selectAll" /> All <br/>
<input type="checkbox" name="checkuser" class="cb_box " /> 1
<input type="checkbox" name="checkuser" class="cb_box " /> 2
<input type="checkbox" name="checkuser" class="cb_box " /> 3

Resource

Sign up to request clarification or add additional context in comments.

Comments

0
$('.selectAll').click(function(){
     $(':checkbox.cb_box').prop('checked', this.checked);    
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.