2

I used jquery to set the checked/unchecked the checkboxes with same class name. I searched web at jquery set checkbox checked. I tried to using prop and attr too. However it doesn't work for me, but I can disable the checkbox. Would someone tell me what I missing.

There is the jquery I used:

 <script language="javascript" src="jquery-2.1.4.js" type="text/javascript"></script>
<script language="javascript" src="jquery-ui-1.11.4/jquery-ui.js" type="text/javascript"></script>

There are the checkbox in page:

<asp:CheckBox ID="chkOne" runat="server" Text="One"  CssClass="optionsBoxes"/>
<asp:CheckBox ID="chkTwo" runat="server" Text="Two"  CssClass="optionsBoxes"/>
<asp:CheckBox ID="chkThree" runat="server" Text="Three"  CssClass="optionsBoxes"/>
<asp:CheckBox ID="chkFour" runat="server" Text="Four"  CssClass="optionsBoxes"/>

My jquery:

$('.optionsBoxes').attr('checked', false);    
$('.optionsBoxes').prop('checked', true);                  
$('.optionsBoxes').attr('disabled', true);  //worked
1

1 Answer 1

1

Does

$('.optionsBoxes')

result in an array of input[type="checkbox"] elements?

You can try this approach:

$('.optionsBoxes').each(function() { $(this).prop('checked', false) });
Sign up to request clarification or add additional context in comments.

4 Comments

I tried your code but it still doesn't work. I added the jquery version in my question. It the version I used cause the problem? Thanks.
@eewardbrosens, I used the developer tool to check the checkbox element. It shows that <span disabled="disabled" class="optionBoxes"><input name="chkOne" id="chkOne" type="checkbox" checkd="checked"/> . The span cause the problem.
I used the nextUntil and closest for looking the input tag, but it still doesn't work. var chk = $(this).closest("input"); chk.prop('checked', false);
Can you show the exact html output in your question?

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.