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

266
Views
How do I remove a 'pointermove' event listner with 'pointerup' event in a JavaScript class?

I'm trying to do the following:

  1. User left clicks and holds down the click, as a user moves their mouse (while holding down left click) the pointer move event will console.log "Pointer Move"
  2. On release of the left click (aka on pointerup event) I want to remove the pointer move event, therefore when a user moves their mouse it will no longer console.log "Pointer move"

I have something now in which my 'pointermove' event is always firing even after I trigger the pointer up event and remove it. You can see it in the log here - after pointer up I don't want it to fire pointer move anymore: enter image description here

Here's the code:

class Controls{
    constructor() {

        this.setControls();
        this.onPointerDown();
    }

    setControls() {
        window.addEventListener("pointerdown", this.onPointerDown);
    }

    onPointerDown(event) {
        window.addEventListener("pointermove", this.onPointerMove);
        window.addEventListener("pointerup", this.onPointerUp);
        console.log("Pointer Down");
    }

    onPointerMove(event) {
        console.log("Pointer Move");
    }

    onPointerUp(event) {
        console.log("Pointer Up");
        window.removeEventListener("pointermove", this.onPointerMove);
        window.removeEventListener("pointerup", this.onPointerUp);
    }
}

let controls = new Controls();
<div>Test</div>

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!