Reputation: 267077
Using jQuery, how can I:
Have all checkboxes on a page turned checked on
or off
?
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!
Upvotes: 2
Views: 4208
Reputation: 1994
1: Set the all to be of the same class and then
$(.classname).attr('checked', true);
Upvotes: 0
Reputation: 417
1: To check all checkboxes
$("input:checkbox").attr('checked', true);
To uncheck all
$("input:checkbox").attr('checked', false);
2:
$("input:checkbox:checked").each(myFunction);
Upvotes: 9
Reputation: 16499
This jQuery Selector will find all checkboxes that have been checked. and this
inside the each function will be assigned to this individual checkbox.
$(":checkbox:checked").each(function(){
doSomething(this);
})
If you want to turn all checkboxes on
then use this:
$(":checkbox").attr("checked","checked")
Upvotes: 1
Reputation:
1- Have all checkboxes on a page turned checked on or off?
Edited: (correction)
$(':checkbox').attr('checked',true);
2- Loop through all the checkboxes on the page which are selected. I.e something like this
$(':checkbox :checked').each(function() {
});
Upvotes: 1