8

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.

0

4 Answers 4

9

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.

Sign up to request clarification or add additional context in comments.

3 Comments

if old Jquery version use .attr()
Thanks it worked, I have additional question. If I click on a link I want to set somehow that the id from link matches value from checkbox? $("a.type_link[id]").click(function (event) {$('input.type_checkbox[value="id"]').prop('checked', true);}
No problem, glad to help. You'd be best to start a new question for that, as there's a fair bit more logic involved.
2

Use attribute equals selector:

$('input.type_checkbox[value=6]').prop('checked', true);

Comments

1

try below code,it should be worked

$(":checkbox[value=6]").prop("checked","true");

or

$("input[type=checkbox][value=6]").prop("checked",true);​

Comments

0
$("input[name='is_checked'][value='"+value+"']").prop("checked", true);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.