I have created a replacement img checkbox for the site I am working on. I can successfully get the checkbox to check, but not to uncheck. I can see this change in Inspect.
What is wrong with the code? There are no errors in the page. Thanks!
HTML is:
<input type="checkbox" id="AcceptTerms_check" name="AcceptTerms_check" style="display:none;">
<img class="chk-img" id="AcceptTerms" onclick="CheckboxClick(this);" src="../../../wp-content/uploads/misc/notselected.png">
<span id="ts-cs-accept">I have read and accepted the terms</span>.
JS is:
function CheckboxClick(element) {
if(jQuery('input:checkbox[name=' + element.id + '_check]').is(":checked")) {
jQuery('input:checkbox[name=' + element.id + '_check]').attr('checked','false');
jQuery(element).attr("src", "../../../wp-content/uploads/misc/notselected.png");
} else {
jQuery('input:checkbox[name=' + element.id + '_check]').attr('checked','true');
jQuery(element).attr("src", "../../../wp-content/uploads/misc/selected.png");
};
};
.prop()instead of.attr()