Reputation: 3165
I just would like to check all my checkboxes with JQuery. These checkboxes are created with JSF.
I tried :
$("input[type=checkbox]").each(
function() {
$(this).prop('checked', true);
// OR
$(this).attr('checked', true);
// OR
$(this).attr('checked', 'checked');
alert($(this).attr('id'));
}
);
nothing works...
Can JSF be the problem ? Value of these checkboxes are linked with some managed bean boolean value.
Thanks for help.
PS : my alert() function returns id of checkboxes properly and JQuery version is :
jQuery JavaScript Library v1.8.1
Upvotes: 0
Views: 3086
Reputation: 3165
Ok, I think I have understood the problem...
when I try this code :
$(":checkbox").prop('checked',true);
$("input[type=checkbox]").each(
function() {
alert($(this).prop('checked'));
}
);
I have always true
values but I see some checkboxes unchecked...
So values are changed but visual stay the same. It's because I use JSF and it's folowwed render :
This checkox is made of some CSS background etc...
So I have to change CSS of parent div (with background...) to make this checkox checked visually since its value is already set to true.
It was just a visual problem, not value problem.
Thank you
Upvotes: 1
Reputation: 23806
Try using the plain DOM:
$("input[type=checkbox]").each(function() { this.checked = true; });
See also:
Setting "checked" for a checkbox with jQuery?
Upvotes: 0
Reputation: 68400
This should do the trick
$(":checkbox").prop('checked',true);
Upvotes: 2