Here is some useful JavaScript that wrote today to change a CSS class based on the state of a checkbox.
function replaceCssClassOnElementBasedOnCheckBoxState(checkboxId, elementToChangeId, checkedCssClassName, uncheckedCssClassName) { var selectedElement = document.getElementById(elementToChangeId); var checkBox = document.getElementById(checkboxId); if(selectedElement && checkBox) { if(checkBox.checked) selectedElement.className = checkedCssClassName; else selectedElement.className = uncheckedCssClassName; } }
For Example:
The style of this div should change based on the state of the checkbox.