javascript - check checkbox if other checkbox with same value is checked jquery -


how check checkbox if other checkbox same value checked. if select 1 should check other div checkbox same value.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>  <div>    <input type="checkbox" value="1">1    <input type="checkbox" value="2">2   </div>  <div>    <input type="checkbox" value="1">1    <input type="checkbox" value="2">2   </div>

as simple gets:

$('input:checkbox').on('change', function(){      //if(this.checked)    // optional, depends on want      $('input[value="' + this.value + '"]:checkbox').prop('checked', this.checked);  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>  <div>    <input type="checkbox" value="1">1    <input type="checkbox" value="2">2   </div>  <div>    <input type="checkbox" value="1">1    <input type="checkbox" value="2">2   </div>

if want others remain checked when uncheck one, @ arun p johny's solution.


Comments