I have a function and I'm trying to set the checkbox to true, in function, this way:
$("#cbpre").checked = true;
But it is not scoring, I've debugged, and it goes into this part, it just does not checkbox.
I have a function and I'm trying to set the checkbox to true, in function, this way:
$("#cbpre").checked = true;
But it is not scoring, I've debugged, and it goes into this part, it just does not checkbox.
$("#cbpre").prop('checked', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputid="cbpre"" type="checkbox">
OU
$("#cbpre").attr('checked','checked')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputid="cbpre"" type="checkbox">
You can use the attr
method or the prop
method of JQuery for this:
$('#ck1').attr('checked', 'checked');
$('#ck2').prop('checked', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><p>Checkbox1:<inputid='ck1'type="checkbox" />
</p>
<p>
Checkbox 2: <input id='ck2' type="checkbox" />
</p>