Browse By

Best Explain How to use check and unchecked checkbox in jquery 2020

Spread the love
How to use check and unchecked checkbox in jquery
How to use check and unchecked checkbox in jquery

HTML code for creating check box.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="checkbox" name="all" id="checkall" />Check All</br>

<input type="checkbox" class="cb-element" /> Checkbox  1</br>
<input type="checkbox" class="cb-element" /> Checkbox  2</br>
<input type="checkbox" class="cb-element" /> Checkbox  3

Jquery Code for check and uncheck

<script>
$("#checkall").change(function () {
    $("input:checkbox").prop('checked', $(this).prop("checked"));
});

$(".cb-element").change(function () {
  if($(".cb-element").length==$(".cb-element:checked").length)
    $("#checkall").prop('checked', true);
  else
    $("#checkall").prop('checked', false);
});
</script>

output:

check all and un check all in jquery

Read this also:

What is PHP?

Basics of PHP

if…else, Switch and loops in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *