@dotalovsky

Как отключать события клика если элементы равны?

function createGameElement(elem) {
           let item = document.createElement('li')

           item.textContent = elem
           item.classList.add('card')

           item.addEventListener('click',saveCard)
        

           function saveCard(){
            this.classList.add('red')

           
            if (firstCardObj !== null && lastCardObj !== null){
                if (firstCardObj.textContent == lastCardObj.textContent) {
                    firstCardObj = null;
                    lastCardObj = null;
                } else{
                    firstCardObj.classList.remove('red')
                    lastCardObj.classList.remove('red')
                    firstCardObj = null
                    lastCardObj = null
                }
            };
            if(firstCardObj == null){
                firstCardObj = this;
            }else{
                if (lastCardObj == null){
                    lastCardObj = this;
                }
            };
            let winCards = document.getElementsByClassName('red').length
            let allCards = document.getElementsByClassName('card').length
            if(winCards == allCards){
                 playAgain()
            }
           };

         return{
             item
         }
       }

       let firstCardObj = null
       let lastCardObj = null


Добрый день,поскажите пожалуйста как применить removeEventListener в случае если пользователь уже выбрал два элемента и они совпали,а то сейчас получается что можно тыкать даже на совпавшие элементы
  • Вопрос задан
  • 59 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы
SummerWeb Ярославль
от 120 000 до 180 000 ₽
КРАФТТЕК Санкт-Петербург
от 60 000 до 80 000 ₽
Brightdata Тель-Авив
от 5 500 до 6 500 $
01 июн. 2024, в 15:46
160000 руб./за проект
01 июн. 2024, в 15:01
5000 руб./за проект
01 июн. 2024, в 14:06
3000 руб./за проект