Y Chan
Y Chan

Reputation: 317

uncheck checkbox with same classname in jquery doesn't work

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

Upvotes: 2

Views: 2048

Answers (1)

edwardbrosens
edwardbrosens

Reputation: 112

Does

$('.optionsBoxes')

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

You can try this approach:

$('.optionsBoxes').each(function() { $(this).prop('checked', false) });

Upvotes: 1

Related Questions