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

99
Views
mouse eventlistener isnt being removed

Im trying to remove an eventlistener that I initialize somewhere in the code and then remove later in a function. I know that you have to remove the same listener that you initialized, but it doesnt seem to be working. I store the eventlistener in a variable that I believe has global scope, so Im not sure what the issue is. The eventlistener itself works fine, and starts as expected.

I have also tried not storing the eventlistener in a variable but that didnt work either.

  mainFunction = function (){
    mousee = document.addEventListener('mouseout', mouseEvent);
    if ($(".message_input").val().replace(/\s/g, "").length > 0){
      unbindAll(true); // unbind all functions
      message = getMessageText();  // retrieve the users message text
      $(".message_input_wrapper").html("");
      printMessage(message, "right"); // display there message on the screen
      if (message=="stop"){
        document.removeEventListener(mousee);
        initiateStopSection();
      } else {
        //async_elipsis();
        response = async_bot(message);
      };
    };
  };

Just for clarification, I was initially using

document.removeEventListener("mouseout", mouseEvent)

but it wasnt working

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

0

When using removeEventListener, you have to pass the event type and the event handler, so in this case you would use

document.removeEventListener("mouseout", mouseEvent)
about 4 years ago · Juan Pablo Isaza Report

0

removeEventListener takes 2 arguments. The first is the event you are trying to target, in this case mouseout, and the second is the function you wish to remove.

For your example it would be this:

document.removeEventListener("mouseout", mouseEvent)

There is no need to set the initial listener to a variable with this implementation.

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!