简体   繁体   中英

check all checkboxes jQuery

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?

Try

jQuery 1.6+

$('#myDiv input:checkbox').prop('checked', true);

jQuery 1.5.x and below

$('#myDiv input:checkbox').attr('checked', true);

Note: $( ":checkbox" ) is equivalent to $( "[type=checkbox]" )

Try this:

 $('#myDiv input:checkbox').attr('checked',true);

As per the accepted answer this only works for jquery 1.5.x and below.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM