Reputation: 63
How with jquery can I make a check all uncheck all selection I have it so I can select each individual one, but with over 20 checkbox's I need to select all or deselect all
<input type="checkbox" name="filters" rel="2" checked="checked" /> name
  <input type="checkbox" name="filters" rel="3" checked="checked" />tname
 <input type="checkbox" name="filters" rel="4" checked="checked" />lname
JQUERY
$(function(){
$(':checkbox').on('change', function(){
$('td').filter(':nth-child(' + $(this).attr('rel') + ')').toggle();
$('th').filter(':nth-child(' + $(this).attr('rel') + ')').toggle();
});
})
Each one will hide a field at this time but would be nice for a check all checkbutton.
Thanks
Upvotes: 2
Views: 982
Reputation: 13213
Use the prop()
function (jQuery v1.6+):
To check all:
$("input[type='checkbox']").prop("checked", true);
To uncheck all:
$("input[type='checkbox']").prop("checked", false);
To check if an input is checked, you can use if (this.checked)
Upvotes: 2