I am attempting to add a require attribute to a closest textarea when my radio field value is NO, I know you can target this specifically but my checklist has a 15 items and I don't want to repeat each function.
My code is below, I am able to get the value but it does not add a required attribute any of the closest textarea.
My HTML
<tr>
<td width="10">1</td>
<td width="650">Does the stencil follow the standard size?</td>
<td width="10"><label><input type="radio" name="q1" value="YES" required></label></td>
<td width="10"><label><input type="radio" name="q1" value="NO" class="noq"></label></td>
<td width="10"><label><input type="radio" name="q1" value="N/A"></label></td>
<td><textarea rows='1' class='autoExpand' name="remarks_q1"></textarea></td>
</tr>
My jQuery
$('.noq').on('click', function(e) {
if(e.currentTarget.value == 'NO'){
$(this).parent().closest('.autoExpand').prop('required',true);
}else{
$(this).parent().closest('.autoExpand').prop('required',false);
}
console.log(e.currentTarget.value);
});
My console log give the correct value, I also tried the prop but no luck, any suggestion would be great! Thanks in advance!