Reputation: 2207
I have a little issue, if i select an single checkbox and press f5 the state of the checbox will remain(so it will be checked) but if i use jQuery to select all checkboxes on a page and then press f5 all of the checkboxes will blank(so uncheck, only the one's that are handpicked will remain in there state). How can i solve this, so that when i hit refresh everything will remain the same?
the code
jQuery('.sellectall').click(function(){
$('input:checkbox').attr('checked',true);
});
Upvotes: 1
Views: 213
Reputation: 322452
I assume you're using jQuery 1.6 or later.
If so, use the prop()
[docs] method instead of the attr()
[docs] method.
Then you should get the same behavior as if a user clicked the box.
jQuery('.sellectall').click(function(){
$('input:checkbox').prop('checked',true);
});
...or set the checked
property manually:
jQuery('.sellectall').click(function(){
$('input:checkbox').each(function() { this.checked = true; });
});
Upvotes: 2