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

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

Войти через центр авторизации
Похожие вопросы
КРАФТТЕК Санкт-Петербург
от 60 000 до 80 000 ₽
Brightdata Тель-Авив
от 5 500 до 6 500 $
Rocket Брянск
от 60 000 до 100 000 ₽
27 мая 2024, в 05:32
3000 руб./за проект
27 мая 2024, в 04:26
1000 руб./за проект