A
A
Alexey2020-05-04 23:46:16
css
Alexey, 2020-05-04 23:46:16

JS adds class but styles are not applied - why?

Guys, help me, I've already broken my head!
I want to change the css styles when I click on the button, the class is added, but the styles are not applied.
5eb07ea6dee81151170996.jpeg
5eb07eb25b776909521300.jpeg

.section {
    padding-top: 110px;
    background-color: #27262b;
    padding-bottom: 110px;
}
.section-light {
    padding-top: 110px;
    background-color: #fffefe;
    padding-bottom: 110px;
}

var buttonchange = document.querySelector(".change");
var section = document.querySelector(".section");

buttonchange.addEventListener("click", function(){
    section.classList.add(".section-light");
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Muravyov, 2020-05-04
@AlexR0v

I understand that you add the class also with a dot, but this is not necessary. You should add additional classes simply with a space. class="class1 class2" - no new dots

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question