I have HTML elements:
<input class="type_checkbox" id="1" name="types[]" type="checkbox" value="1">
<input class="type_checkbox" id="0" name="types[]" type="checkbox" value="6">
I want to set checkbox true with jQuery where value is equal to 6. Pls help.
Reading a Checkbox When using jQuery and you wish to read whether a checkbox is checked or not. $('#checkboxid').is(':checked'); This will return true if the checkbox is checked and false if left unchecked.
To get the value of the Value attribute you can do something like this: $("input[type='checkbox']"). val();
You can use the attribute selector along with prop()
to set the checked
property.
$('input.type_checkbox[value="6"]').prop('checked', true);
You can obviously amend the input.type_checkbox
part of the selector to better suit your needs.
Use attribute equals selector:
$('input.type_checkbox[value=6]').prop('checked', true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With