I can’t figure out how to get .each working when using a relative path (rather than just the class name). This works in properly checking if the radio button is selected, however it then proceeds to make .radio_select show for both of them. So it’s clearly just checking the first value, then applying the results to both, when I would like it to check both individually. Can anyone figure out what it is I’m doing incorrectly? Is there a better way I could be doing this? Any help is appreciated, thank you.
<div id='pid'></div>
<div class='comment_reply_holder'>
<div class="radio_holder">
<div class='radio_select'>
<input class='hidden_radio' type='radio' checked='true'>
</div>
</div>
<div class="radio_holder">
<div class='radio_select'>
<input class='hidden_radio' type='radio'>
</div>
</div>
</div>
<script>
radio = $('#'+pid).next('.comment_reply_holder').children().find('.radio_holder');
radio.each(function() {
if (radio.children().find('.hidden_radio').prop("checked") == true) {
radio.children().find('.radio_select').show();
}
});
</script>
Note: The “pid” div is created dynamically on the site, which is why I’m grabbing the information in this manner if you are wondering why I’m even creating the path to it this manner.
Just use
this(i.e. the currently iterated element) inside the callback function, not your external variableradio.