1

I have some problem with checkboxes and changing its state by JavaScript and jQuery.

When I try to change attribute "checked" by this jQuery code, its works perfectly:

jQuery("input[type='checkbox']").prop("checked", false);

But, if I need change attribute by specific attribute it doesn't work (attribute changed, by checkbox is still select):

jQuery("#id").prop("checked", false);

How can I change "checked" attribute by ID?

5
  • does that id exist and is it unique..? Commented Jun 10, 2014 at 5:24
  • IDs may be of asp.net server controls! Is It? Commented Jun 10, 2014 at 5:24
  • when you change the checked state of a checkbox... the attribute is not changed instead an internal property of the dom element is changed Commented Jun 10, 2014 at 5:25
  • Did you checked your console log for errors. Commented Jun 10, 2014 at 5:26
  • Post your markup or a fiddle. Commented Jun 10, 2014 at 5:26

3 Answers 3

1

Try This,

$('input[type='checkbox'][value='value_to_be_checked']').prop('checked',true);

Mention value of checkbox to be checked.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the method prop like the following fiddle : http://jsfiddle.net/3qp99/1/

Comments

0

Try simpley with it (If you want a pure JS solution without using jQuery)

document.getElementById("myId").checked = true; // check
document.getElementById("myId").checked = false; //uncheck

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.