I'm making a basic website that allows users to hide/show checkbox when a button is clicked. However, I need to click the button twice to get it to work. Any idea why?
function myFunction() {
var check_box = document.getElementById('checkbox');
if (check_box.style.display === "block") {
check_box.style.display = "none";
} else {
check_box.style.display = "block";
}
}
<button id="button" onclick="myFunction()">
Show/Hide Checkbox
</button>
<input type="checkbox" id="checkbox">