Jquery Checkbox Check All Example - Jquery

How to check and uncheck all checkboxes using jquery?

Snippet Code


  
Rate this page :
  [ 0 votes]

This simple code is used for multiple selection of check/uncheck the checkboxes. According to user all the check box will select and unselect accordingly. The below code is used to check/uncheck the required field.

<script type='text/javascript'> $(function(){ $(".chkbox").click(function(){ if($(".chkbox").length == $(".chkbox:checked").length) { $("#checkall").attr("checked", "checked"); } else { $("#checkall").removeAttr("checked"); } }); $("#checkall").click(function () { $('.chkbox').attr('checked', this.checked); }); }); </script> <table border="1" align='center'> <tr> <th><input type="checkbox" id="checkall"/></th><th>Fruits</th> </tr> <tr> <td align="center"><input type="checkbox" class="chkbox" name="chkbox" value="1"/></td><td>Apple</td> </tr> <tr> <td align="center"><input type="checkbox" class="chkbox" name="chkbox" value="2"/></td><td>Orange</td> </tr> <tr> <td align="center"><input type="checkbox" class="chkbox" name="chkbox" value="3"/></td><td>Mango</td> </tr> <tr> <td align="center"><input type="checkbox" class="chkbox" name="chkbox" value="4"/></td><td>Grapes</td> </tr> <tr> <td align="center"><input type="checkbox" class="chkbox" name="chkbox" value="5"/></td><td>Banana</td> </tr> </table>

Tags


Ask Questions

Ask Question