Click here to Skip to main content
15,937,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am checking the checkbox dynamically using code $("#chkBrand").attr('checked',true)/
$("#chkBrand").attr('checked','checked')/$("#chkBrand").prop('checked',true) which i can see in DOM but no action is taken on checkbox. It remains unchecked.

Can anybody please help me to solve this.

Thanks,
Afzal
Posted
Comments
Kornfeld Eliyahu Peter 24-Mar-15 5:41am    
See this, and check if you spot the difference...
http://jsfiddle.net/oax3rsp1/

1 solution

Should be the following:

JavaScript
$('#chkBrand').prop('checked', true);
$('#chkBrand').prop('checked', false);


Although your query selector assumes that you've assigned chkBrand as the element id on the checkbox.

If you've only assigned it to name, this will not work.

HTML
<input type="checkbox" id="chkBrand" />


Taken from here:

http://stackoverflow.com/questions/426258/checking-a-checkbox-with-jquery[^]
 
Share this answer
 
v3
Comments
afzalkarani 24-Mar-15 5:45am    
I have use checkbox like below
<input type="checkbox" id="chkExcludeBrand" name="chkExcludeBrand"/>
Stephen Hewison 24-Mar-15 5:48am    
then the id is chkExcludeBrand. Use:

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

The portion in the first bracket is a CSS query selector which needs to match the elements you're looking to amend.

http://www.w3schools.com/cssref/css_selectors.asp
afzalkarani 24-Mar-15 5:51am    
I've used but no result. Although in DOM it is checked.
afzalkarani 24-Mar-15 5:59am    
Hi,

i have added simple checkbox
Check: <input id="idChk" type="checkbox" />

And I am trying to get id checked from DOM Console. it shows checked but cannot see it ticked.
Thanks7872 24-Mar-15 5:49am    
Did you try what he stated?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900