noob-1 noob-1 - 2 months ago 6
HTML Question

How to select and check these types of checkboxes based on values?

<span class="answerBox">
<a name="checkboxtag" class="largecheckbox" onclick="selectQuestionAnswer(this);"></a>
<input name="answers" value="8ad6a4124641ec5001464d856b23436c" class="checkbox displaynone" type="radio">
</span>


I've tried using .prop()

jQuery('input:checkbox[value="8ad6a4124641ec5001464d856b23436c"]').prop("checked", true);


Tried to just trigger a click:

jQuery('input:checkbox[value="8ad6a4124641ec5001464d856b23436c"]').trigger('click');


Tried editing its sibling's class (because on click, it changes the sibling's class and nothing else):

jQuery('input:checkbox[value="8ad6a4124641ec5001464d856b23436c"]').siblings('.largecheckbox').trigger('click');


Then I wasn't so sure if I was even selecting it correctly. I tried to toggle highlight on the checkbox but it doesn't do anything..

jQuery('input:checkbox[value="8ad6a4124641ec5001464d856b23436c"]').siblings('.largecheckbox').toggle('highlight');
jQuery('input:checkbox[value="8ad6a4124641ec5001464d856b23436c"]').toggle('highlight');


Is it just not possible to select this checkbox? I've been trying all day yesterday and today.

Thanks for reading and any help!

Edit: you guys are gods. IT WORKS. I used
jQuery('input:radio[value="8ad6a4124641ec5001464d856b23436c"]').siblings().toggle('highlight');


to just make sure it worked AND IT DOES. THANK YOU.
Then I used trigger('click'); and it did. All I had to do was select it using the radio selector. Thank you everyone for your efforts.

Answer

You are trying to change an <input type="radio"> with a checkbox selector

Fix one or the other to what it is supposed to be

Your code works fine when you change to

<input name="answers" value="8ad6a4124641ec5001464d856b23436c" type="checkbox">

If you want to leave as radio use :radio selector

DEMO