I want to show a div on checking a checkbox and hide the div on unchecking the checkbox.This is what I tried.It works only on checking and unchecking and then checking. I am using jquery 3.5.1.
I think there is a problem with this jquery part logic
jquery part
$('.frameopener').on('change', function(){ // on change of state
if(this.checked) // if changed state is "CHECKED"
{
var formid=$(this).attr("id");
$("#"+formid+"").click(function() {
$("#" + formid + "form").toggle();
});
}
});
php part which dynamically displays checkbox from a loop
echo '
<td>
<input type="checkbox" class="frameopener" id="'.$checkboxitemsafterstripper[$key].'" ></td><td>'.
$item.'
</td>';
Here is the frame which needs to be toggled
foreach( $checkboxitemsafterstripper as $key => $item ){
echo '
<div id="'.$item.'form">';
}