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

190
Views
Remove eventlistener

Help:-) How do i remove this listener?

this.overlay.addEventListener('click', this._handlePlay.bind(this));

_handlePlay looks like this:

_handlePlay() {
    this._isOpen = !this._isOpen;
  }

i tried...

this.overlay.removeEventListener('click', this._handlePlay.bind(this));

and more desperately:

this.overlay.removeEventListener('click', this._handlePlay());

but the listener wont leave the scene?

I have the bind as I am in js and web component context

/regards

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

0

The function you pass to removeEventListener needs to be the same function that you pass to addEventListener.

bind creates a new function.

this.overlay.addEventListener('click', this._handlePlay.bind(this));

Since you don't keep the value of this._handlePlay.bind(this), there's no way to get that function back to pass it to removeEventListener.


You need to keep the value somewhere that you can access when you later try to remove the event listener.

const boundHandlePlay = this._handlePlay.bind(this);
this.overlay.addEventListener('click', boundHandlePlay);
this.overlay.removeEventListener('click', boundHandlePlay);
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!