Reputation: 189
I have some web page with input fields in it and one of them is a checkbox, I'm trying to create 'clear all' button to clear all values including checkbox 'v'.
I tried $('#check5').removeAttr('checked');
and $('#check5').attr('checked',false);
.
But it works only after pressing F5, and I would like to change the attribute status without refreshing the page. Any idea ?
Upvotes: 1
Views: 161
Reputation: 11
You can use this code:
To uncheck:
$('#check5').prop('checked',false);
To check:
$('#check5').prop('checked',true);
Upvotes: 1
Reputation: 3293
following code is working for me.
$(':input').not(':button, :submit').val('').removeAttr('checked').removeAttr('selected');
It clear all the input type fields inside form.
Upvotes: 0
Reputation: 171
If you are aiming at the specific checkbox,
$('#check5').prop('checked',false);
If not, below given resets all the checkboxes in the page.
$("input[type=checkbox]").prop("checked", false);
Upvotes: 1
Reputation: 1464
The checked attribute is a property, try using this:
$("input[type=checkbox]").prop("checked", false);
this will make all checkbox's on a page unchecked.
Upvotes: 1
Reputation: 4205
If you mean how to remove the 'checked' state from all checkboxes:
$('input:checkbox').removeAttr('checked');
Example:
$(document).ready(function(){
$('.check:button').toggle(function(){
$('input:checkbox').attr('checked','checked');
$(this).val('uncheck all');
},function(){
$('input:checkbox').removeAttr('checked');
$(this).val('check all');
})
})
Upvotes: 2