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

127
Views
removeEventListener on anonymous function with mouseover event

I am trying to remove a eventListener that calls an anonymous function with the mouseover and mouseout events.

const playerPlace = (ships,player,computer,ship) => {
    let playerBoard = document.getElementById('playerGameboard');
    playerBoard.addEventListener('mouseover', (e) => playerHover(ship,e))
    playerBoard.addEventListener('mouseout',(e) => playerExit(ship,e))
    playerBoard.addEventListener('click',function(event){
        let element = event.target.id;
        player.playerPlace(ship,parseInt(element[0]),parseInt(element[1]),'horizontal');
        updateGameboard(player,computer);
        ship.isPlacedSetter(true);
        if(isShipPlaced(ships) !== true){
            console.log('remove Listener')
            playerBoard.removeEventListener('mouseover',playerHover);
            playerBoard.removeEventListener('mouseout',playerExit);
            playerPlace(ships,player,computer,isShipPlaced(ships))

        }
    }, {once:true})
} 

I can't find any solutions to my problem online.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should use removeEventListener('eventName',function() {/*your anonymus function*/})

about 4 years ago · Juan Pablo Isaza Report
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!