Задать вопрос
@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);
});
  • Вопрос задан
  • 59 просмотров
Подписаться 1 Простой Комментировать
Пригласить эксперта
Ответы на вопрос 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";
}
Ответ написан
Ваш ответ на вопрос

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

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