Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
Can't remove eventlistener declared in for cycle
  function roleDescription() {
    // вторая ступень = описание роли при наведении, выбор роли при клике
    for (let i = 0; i < originDescription.length; i++) {
      buttons[i].addEventListener('mouseover', asignDesc.bind(buttons[i], i));
      buttons[i].addEventListener('click', asignRole.bind(buttons[i], i), {
        once: true
      });
    }
  }

  function asignRole(i) {
    playerrole = role[i];
    alert(playerrole);
    makeSpecial();
  }

  function asignDesc(i) {
    maintext.textContent = originDescription[i];
    maintext.style.fontSize = '15px';
  }

  function makeSpecial() {
    // третья ступень - подтирание следов от выбора роли, смена кнопок на другие
    for (let i = 0; i < originDescription.length; i++) {
      buttons[i].removeEventListener('mouseover', asignDesc.bind(buttons[i], i));
      buttons[i].removeEventListener('click', asignRole.bind(buttons[i], i), {
        once: true
      });
    }
  }

i have four buttons for player to choose from and i want to player when he clicks one buttons function to assign role will be removed and he could proceed to the next step. i've declared buttons from the cycle and tried to remove buttons from the cycle, but no luck. how can i remove buttons without making very long code? or where am i mistaken with that one?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda