0

Now I'm practicing Javascript and I need some helps from you guys.

https://codepen.io/domrongpon-tanpaibul/pen/YzGyBZq?editors=1111

closeBtn.addEventListener('click', () => {
    if (this.dispatchEvent(new CustomEvent('close-dlg', {cancelable: true}))) {
        div.style.display = "none";
    }
})  

I think the solution is to use removeEventLister but the problem is I need it on anonymous function without assigning function name.

Are there any solutions to solve this?

0stone0
  • 34,288
  • 4
  • 39
  • 64
Tan
  • 35
  • 3
  • 6
  • 1
    Couldn’t you store your function in a variable, if you want to remove this specific listener only? – insertusernamehere Apr 07 '22 at 09:32
  • 1
    What the above comment said or just don't make it anonymous. – Joosep Parts Apr 07 '22 at 09:33
  • 1
    *"I need it on anonymous function without assigning function name"* Why do you *need* this? There is no difference between a named and an unnamed function at runtime (at least as far as the JavaScript engine is concerned). – Felix Kling Apr 07 '22 at 09:33
  • Yeah the solution is just naming the handler function. – anotherOne Apr 07 '22 at 09:34
  • Does this answer your question ? https://stackoverflow.com/questions/4386300/javascript-dom-how-to-remove-all-event-listeners-of-a-dom-object – albjerto Apr 07 '22 at 09:35
  • sadly that quiz rule's not to modify anythings on parent class (assign as variable, assign function name ) – Tan Apr 07 '22 at 09:36
  • So you are asking us to solve the quiz for you? That seems to defeat the purpose of doing the quiz in the first place. – Felix Kling Apr 07 '22 at 09:51

0 Answers0