1

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 ?

Louis 'LYRO' Dupont
  • 1,052
  • 4
  • 15
  • 35
user3035279
  • 189
  • 1
  • 1
  • 8
  • 3
    Possible duplicate of [Setting "checked" for a checkbox with jQuery?](https://stackoverflow.com/questions/426258/setting-checked-for-a-checkbox-with-jquery) – always-a-learner Aug 03 '17 at 12:18
  • Possible duplicate as mentioned by @ankitsuthar. Good detail guide is given in https://stackoverflow.com/questions/426258/setting-checked-for-a-checkbox-with-jquery. – TechnoCrat Aug 03 '17 at 12:32

6 Answers6

4

You can use this

$('#check5').prop('checked', false);
Jay
  • 703
  • 9
  • 21
2

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');        
    })
})

DEMO

Chandra Kumar
  • 4,127
  • 1
  • 17
  • 25
1

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.

Sean
  • 1,444
  • 1
  • 11
  • 21
1

You can use this code:

To uncheck:

$('#check5').prop('checked',false);

To check:

$('#check5').prop('checked',true);
Azeem
  • 11,148
  • 4
  • 27
  • 40
1

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);
CCoder
  • 151
  • 12
0

following code is working for me.

$(':input').not(':button, :submit').val('').removeAttr('checked').removeAttr('selected');

It clear all the input type fields inside form.

Star
  • 3,222
  • 5
  • 32
  • 48