• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

problems with event listeners on various frames

Participant ,
Feb 26, 2021 Feb 26, 2021

Copy link to clipboard

Copied

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.

 

Views

251

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 26, 2021 Feb 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.

Votes

Translate

Translate
LEGEND ,
Feb 26, 2021 Feb 26, 2021

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 26, 2021 Feb 26, 2021

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines