Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!