javascript - select all checkbox in header , to select all checkboxes in that column -


i have used code:

<script type="text/javascript">   $(window).load(function () {     $(document).delegate(".checkall", "click", function(event) {       $(this).closest("table").find(':checkbox').attr('checked', this.checked);     });   }); </script> 

this code working fine when select/deselect checkbox in header first time. when again select checkbox code not working. checkboxes not selected.

you should use .prop() instead of .attr(). , have check if element checked.

...   var $checkbox = $(this).closest("table").find(':checkbox');   if ($checkbox.is(':checked')) $checkbox.prop('checked', false);   else                          $checkbox.prop('checked', true); ... 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -