I'm trying to use JavaScript to toggle the checkbox status when clicking a button. The first button is supposed to uncheck the box and it's working correctly:
function clear() {
document.getElementById("check").checked = "";
}
However, I also have another button that should check the box if it's not checked and uncheck it if it is already checked. The code below doesn't seem to uncheck the box, even though switching the if statement works in the opposite way. Can anyone help me identify the issue?
function switchIt() {
if (document.getElementById("check").checked !== "checked") {
document.getElementById("check").checked = "checked";
} else {
document.getElementById("check").checked = "";
}
Any assistance would be greatly appreciated! Thank you!