Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery checkboxes manipulation

Using jQuery, how can I:

  1. Have all checkboxes on a page turned checked on or off?

  2. Loop through all the checkboxes on the page which are selected. I.e something like this

    $(sel-cboxes).each(myFunction);
    

So myFunction would be called on each selected checkbox.

Thanks in advance!

like image 349
Ali Avatar asked Apr 22 '26 18:04

Ali


1 Answers

1: To check all checkboxes

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

To uncheck all

$("input:checkbox").attr('checked', false);

2:

$("input:checkbox:checked").each(myFunction);
like image 124
gustavlarson Avatar answered Apr 24 '26 06:04

gustavlarson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!