Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

How to uncheck checkbox using jQuery?

i have a problem with checkboxes , even if i change -- check = "unchecked"

user-image
Question ajoutée par Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.
Date de publication: 2013/04/10
Zaid Rabab'a
par Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.

i try this and it working :D $("#id").prop('checked', true); i think it same as Mariusz Walczyk said :D

Utilisateur supprimé
par Utilisateur supprimé

Try: $('#checkbox_id').attr('checked', false);

Mohammed Sallam
par Mohammed Sallam , Full-stack Software Engineer , Freelancing

I usually use this: $('#id').removeAttr('checked');

Use prop() not attr() for this as attr() will not work in newer versions of jquery. Do jquery uncheck checkbox

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

 

 

Muhammad Ahsan Mirza
par Muhammad Ahsan Mirza , Software Development Engineer , Remit Anywhere Solutions

To uncheck a check box, use $("#id").attr('checked',false); or simply remove the attribute like $("#id").removeAttr('checked');

Hazem Salama
par Hazem Salama , Senior Member of Technical Staff , Verizon Communications

I'd have to second people who suggested you use $('#id').prop('checked', false) vs using attr() Prior to jQuery 1.6, jquery did not make a distinction between what's a property and what is an attribute of the element, and everything was handled via attr(), which made it a beast.
As of 1.6, they made the decision to handle properties via prop, which is meant to be more cross-browser.
For detailed explanation see this http://blog.jquery.com/2011/05/10/jquery-1-6-1-rc-1-released/

Zaher Hazeem
par Zaher Hazeem , Senior Software Engineer , N2V - Startappz

try this, it's fast way to swap the current value, from check to unchecked and vice versa: Check Me

Utilisateur supprimé
par Utilisateur supprimé

this will change the value:

$("#theChk").prop("checked",true)

this will get you the value:

$("#theChk").prop("checked") or $("#theChk").attr("checked")

Abdullah Akram
par Abdullah Akram , Full Stack Developer , Ertekaz Technology

I think answer to your solution is here: just copy paste to your editor,n locate the jquery pakage.
n just try to check uncheck with a single button...cheers!!!!! jQuery check / uncheck a check box example jQuery check / uncheck a check box example Check Me

حماده احمد ابوزيد
par حماده احمد ابوزيد , Senior Web Developer , Pixel for information technology

<inputtype="checkbox"id="myCheckbox"checked="checked"/><!-- Checked --><inputtype="checkbox"id="myCheckbox"/><!-- Unchecked --> $('#myCheckbox').attr('checked',true);// Checks it $('#myCheckbox').attr('checked',false);// Unchecks it

However, you cannot trust the .attr() method to get the value of the checkbox (if you need to). You will have to rely in the .prop() method.

So, for jQuery 1.6+

Use the new .prop() function as:

$('#myCheckbox').prop('checked', true); // Checks it $('#myCheckbox').prop('checked', false); // Unchecks it

Muhammad Awais Mughal
par Muhammad Awais Mughal , Senior PHP Developer , Bookme.pk

<inputtype="checkbox"id="myCheckbox"checked="checked"/><!-- Checked --><inputtype="checkbox"id="myCheckbox"/><!-- Unchecked -->$('#myCheckbox').prop('checked',true);// Checks it $('#myCheckbox').prop('checked',false);// Unchecks it

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?