I have several checkboxes and divs. I would like to toggle the divs based on the checkboxes. I tried toggling the divs using ternary but it isn't working as I expected. Below is the js. I do not want to use jQuery.
function toggle(flavor){
var checkBox = document.getElementById(flavor)
checkBox === true ? document.getElementById(flavor+"Div").style.display = "block" : document.getElementById(flavor+"Div").style.display = "none";
}
Here's the error I get: pen.js:4 Uncaught TypeError: Cannot read property 'style' of null
Here's the pen
Thanks for any help you can provide.