Skip to main content
Inspiring
February 26, 2021
Answered

problems with event listeners on various frames

  • February 26, 2021
  • 1 reply
  • 486 views

FRAME1

this.btn.addEventListener("click", clickHandler.bind(this)); - works great

 

FRAME2

this.btn2.addEventListener("click", clickHandler2.bind(this)); - doesn't work

 

I used the same code and just appended 2 - btn2 and clickHandler2.

I even created a new button btn2 (with an instance etc...)

 

As it didn't work I thought there may be a problem with the event listeners so I removed them

from frame1

this.btn.removeEventListener("click", clickHandler);

I'm afraid the btn2 still doesn't work on frame2.

 

    This topic has been closed for replies.
    Correct answer ClayUUID

    Whenever something doesn't work that you think should, always, ALWAYS verify your assumptions.

     

    Does this.btn2 exist?

     

    Does clickHandler2 exist?

     

    Does clickHandler2 actually execute?

     

    And I don't mean verify with your eyeballs. I mean verify with code that explicitly accesses the variable or function or object, and displays an alert or console.log or whatever with the result of that access.

    1 reply

    ClayUUIDCorrect answer
    Legend
    February 26, 2021

    Whenever something doesn't work that you think should, always, ALWAYS verify your assumptions.

     

    Does this.btn2 exist?

     

    Does clickHandler2 exist?

     

    Does clickHandler2 actually execute?

     

    And I don't mean verify with your eyeballs. I mean verify with code that explicitly accesses the variable or function or object, and displays an alert or console.log or whatever with the result of that access.

    Inspiring
    February 26, 2021

    Excellent answer. I'm a teacher too, I like your style and your profile picture, slightly menacing lol.

    Everything exists but you made me go over everything with a fine-tooth comb.

    The btn2 button was not placed where it was supposed to be.

    Cheers