Задать вопрос
@RomanMotsar

Как поменять цвета элементов которые стали белыми обратно на красный?

const months = document.querySelector(".months");

const monthArr = Array.from(months.children);
console.log(monthArr);

const clickMount = (event) => {
  let currentMonth = event.currentTarget;
  currentMonth.style.backgroundColor = "red";
  if (currentMonth.style.backgroundColor == "red") {
    currentMonth.style.backgroundColor = "white";
  } else if ((currentMonth.style.backgroundColor = "white")) {
    currentMonth.style.backgroundColor = "red";
  }
};

monthArr.forEach((month) => {
  month.addEventListener("click", clickMount);
});
  • Вопрос задан
  • 60 просмотров
Подписаться 1 Простой Комментировать
Помогут разобраться в теме Все курсы
  • Яндекс Практикум
    Фронтенд-разработчик
    10 месяцев
    Далее
  • Skillfactory
    Профессия Веб-разработчик
    12 месяцев
    Далее
  • Нетология
    Fullstack-разработчик на Python + нейросети
    20 месяцев
    Далее
Пригласить эксперта
Ответы на вопрос 1
NikFaraday
@NikFaraday
Student full-stack Developer
if (currentMonth.style.backgroundColor == "red") {
currentMonth.style.backgroundColor = "white";
} else if ((currentMonth.style.backgroundColor = "white")) {
currentMonth.style.backgroundColor = "red";
}


=>

if (currentMonth.style.backgroundColor == "red") {
currentMonth.style.backgroundColor = "white";
} else {
currentMonth.style.backgroundColor = "red";
}
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы