I have simple function in which I change the default styling of text when a checkbox is checked, and change the styling back to default when checkbox gets unchecked.
The terms.style = ""; should reset the style back to default, but for some reasons it doesn't, and I have absolutely no idea why. I know that the else scope is performed when checkbox gets unchecked, as I have tested it with manually entering different style.
const form = document.getElementById('form');
const checkBox = form.querySelector('input[name=termsCheckBox]');
checkBox.addEventListener('click', function(){
const terms = document.getElementById('termsText');
if (checkBox.checked){
terms.style = "color: black; font-weight: normal";
} else {
terms.style = "";
}
});//end of function
element.styleis a read-onlyObject. Either useelement.setAttribute('style', 'color: black; font-weight: normal')or useelement.style.cssText = 'color: black; font-weight: normal'.styleattribute that you want to back to default?