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 ?

2

6 Answers 6

4

You can use this

$('#check5').prop('checked', false); 
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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.

Comments

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

Comments

1

You can use this code:

To uncheck:

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

To check:

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

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.