-1
I am trying to clean the body class without having to put this amount of code in if/Else
function bgColor(event) {
evento = event.target
if (evento.classList.value == 'vermelho') {
body.classList.remove('blue')
body.classList.remove('yellow')
body.classList.add('red')
}
else if (evento.classList.value == 'azul') {
body.classList.add('blue')
body.classList.remove('red')
body.classList.remove('yellow')
}
else {
body.classList.add('yellow')
body.classList.remove('red')
body.classList.remove('blue')
}
Marcelo, put the example code and add more information about what you are developing, so we can help you. Otherwise people are negatively questioning you. What language are you using? Are you using any framework? etc...
– Mauro Rocha
If body no longer has any class other than these, you can use the classname property. If you have more classes or if it is possible that in the future it will acquire more classes, you could use an object to map the event target value to the class you want to implement.
– user201467