I have searched Stack Overflow and can't quite find the solution. I have this HTML and I want the JQuery to change the text in a box with an id = 'attrib-explain'
when the user clicks on the checkbox.
jQuery('#bapf_1').change(function() {
var privdesc = '<h3>New Title</h3>Clicked on 53';
if(jQuery('#bapf_1_53').checked) {
jQuery('#attrib-explain').html(privdesc);
} else {
jQuery('#attrib-explain').html('');
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<div class="bapf_sfilter bapf_ckbox bapf_asradio bapf_radio_chck" data-op="OR" data-taxonomy="pa_age" data-name="AGE" id="bapf_1"><div class="bapf_head"><h3 style="--fontSize:24; line-height: 1.3;" data-fontsize="24" data-lineheight="31.2px" class="fusion-responsive-typography-calculated">AGE</h3></div><div class="bapf_body"><ul><li><input data-name="10+ years" id="bapf_1_56" type="checkbox" value="56"><label for="bapf_1_56">10+ years</label></li><li class="checked"><input data-name="3 - 5 years" id="bapf_1_53" type="checkbox" value="53" ><label for="bapf_1_53">3 - 5 years</label></li><li><input data-name="5 - 7 years" id="bapf_1_54" type="checkbox" value="54"><label for="bapf_1_54">5 - 7 years</label></li><li><input data-name="7 - 10 years" id="bapf_1_55" type="checkbox" value="55"><label for="bapf_1_55">7 - 10 years</label></li></ul></div></div>
<div id='attrib-explain' style='padding:10px; background:#e2e2e2; width: 100%'>Text to go here</div>