When I add .className to change the style of something with or without an event, it does not replace previous styles, such as color, it will add new style properties, but it will not replace the old with new ones.
var loadbutton = document.getElementById('initialbutton');
var loadtext = document.getElementById('altertext');
var mainfunc = function(){
loadtext.className = "changedtext";
}
loadbutton.addEventListener("click",mainfunc,false)
color:
font-weight:bold;
}
.changedtext {
color:
font-style:italic;
font-size:24px;
}
first ID is the original style, and the class is the class I want to apply. Therefore, onclick will apply the changed "font style" and change the "font size", but the color will remain red. I want him to replace red with a new color
source
share