Reputation: 1477
I have this code:
if $('#myDiv').find('input[type=checkbox]:checked').removeAttr('checked');
Unchecks all checkboxes is there a line of code that will add the check to all of the checkboxes without looping each checkbox?
I've tried:
$('#myDiv' input[type="checkbox"]').prop('checked', $(this).prop('checked'))
;
But that did not work. Can someone help me?
Upvotes: 0
Views: 82
Reputation: 157
Try this:
$('#myDiv input:checkbox').attr('checked',true);
As per the accepted answer this only works for jquery 1.5.x and below.
Upvotes: -1
Reputation: 1148
Try
$('#myDiv input:checkbox').prop('checked', true);
$('#myDiv input:checkbox').attr('checked', true);
Note: $( ":checkbox" )
is equivalent to $( "[type=checkbox]" )
Upvotes: 3