Uncheck the box that is checked by the user

When I check the boxes and uncheck the boxes, the browser does not set the set attribute. So, when I try to uncheck using jquery:

$('#tab2 input').removeAttr('checked');

he does not work. It checks the checkbox checkbox on my javascript code. How can I uncheck a box that has already been verified by the user?

+3
source share
3 answers

You set the property, so use .prop()in jQuery 1.6.

$('#tab2 input').prop('checked',false);

Or, if only one input, just change the property of the element directly.

$('#tab2 input')[0].checked = false;

jQuery 1.6.1 , jQuery 1.6.1, .attr(), , .prop() .

:

, , , , readonly 1.6.1, , jQuery 1.6. , ,

$(":checkbox").attr("checked", true);
$("option").attr("selected", true);
$("input").attr("readonly", true);
$("input").attr("disabled", true);

:

if ( $(":checkbox").attr("checked") ) { /* Do something */ }

1.6.1, , .

+5
$('#tab2 input').attr('checked',false);
+3
$('input[name=foo]').attr('checked', false);
+2
source

All Articles