0

I have few div and ulelements which has several checkboxes inside. I need to uncheck those for some selected div and ul.

I tried something like this which works only for .cd-filter-content-alt,

 $('.margin_float_metric, .cd-filter-content-alt input[type=checkbox]').prop('checked', false);

I know that we can use it separately to uncheck. But for some reasons i need those inside a single line.

Something like we have for click,

 $('#buttonA, #buttonB, #buttonC').click(function (e) {
});

Any possibilities?

A Coder
  • 3,039
  • 7
  • 58
  • 129

2 Answers2

0

Look at this example.

$("#checkAll").change(function() {
  $("input:checkbox").prop('checked', $(this).prop("checked"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<label><input type="checkbox" id="checkAll"/> Check & uncheck all</label>

<div>
  <ul>
    <li><label><input type="checkbox" /> Option 1</label></li>
    <li><label><input type="checkbox" /> Option 2</label></li>
    <li><label><input type="checkbox" /> Option 3</label></li>
    <li><label><input type="checkbox" /> Option 4</label></li>
  </ul>
</div>
 

I hope this helps you :)

Kung Fu Panda
  • 636
  • 10
  • 22
  • 1
    That is not his problem. I believe his problem is a selector issue. If your code answers his issue, then this is a duplicate: http://stackoverflow.com/questions/5229023/jquery-check-uncheck-all-checkboxes-with-a-button – mplungjan Apr 06 '17 at 06:42
0

If you want to uncheck checkboxes by seperated buttons from seperated divs, this example may be helpful.

$(document).ready(function () {

    $(".resetDiv").on('click', function () {
        $(this).parent().find("input:checkbox").prop('checked', false);
    });

});
 <script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>

   
<div>
 <input type="Button" Value="Dv1Res" class="resetDiv">
  <ul>
    <li><label><input type="checkbox" /> Check div1-1</label></li>
    <li><label><input type="checkbox" /> Check div1-2</label></li>
    <li><label><input type="checkbox" /> Check div1-3</label></li>
    <li><label><input type="checkbox" /> Check div1-4</label></li>
  </ul>
</div>
 <div>
  <input type="Button" Value="Dv2Res" class="resetDiv"/>
  <ul>
    <li><label><input type="checkbox" /> Check div2-1</label></li>
    <li><label><input type="checkbox" /> Check div2-2</label></li>
    <li><label><input type="checkbox" /> Check div2-3</label></li>
    <li><label><input type="checkbox" /> Check div2-4</label></li>
  </ul>
</div>
ReadyFreddy
  • 898
  • 8
  • 20