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:

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.

Kornfeld Eliyahu Peter 24-Mar-15 5:41am    
See this, and check if you spot the difference...

1 solution

Should be the following:

$('#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.

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

Taken from here:[^]
Share this answer
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.
afzalkarani 24-Mar-15 5:51am    
I've used but no result. Although in DOM it is checked.
afzalkarani 24-Mar-15 5:59am    

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