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

Dynamic naming

Community Beginner ,
Dec 21, 2017 Dec 21, 2017

Hi, this is not working and i don't understand why.

First i add an eventlistener

var couverture_out=rollout.bind(this,'couverture');

this.couverture.addEventListener("mouseout",couverture_out);

then, i want to remove it on a click on the object

this.couverture.addEventListener("click", obj_bon.bind(this,'couverture'));

function obj_bon(obj) {

    var obj_out =  [obj]+"_out";  /* give 'couverture_out' */

    this[obj].removeEventListener("mouseout", obj_out);

}

this[obj].removeEventListener("mouseout", obj_out);

should give

this.couverture.removeEventListener("mouseout",couverture_out)  but that is not working, mouseout is still active

thanks for your help

172
Translate
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

Community Expert , Dec 21, 2017 Dec 21, 2017

use:

this.couverture_out=rollout.bind(this,'couverture');

this.couverture.addEventListener("mouseout",this.couverture_out);

this.couverture.addEventListener("click", obj_bon.bind(this,'couverture'));

function obj_bon(obj) {

    this[obj].removeEventListener("mouseout", this[obj+"_out"]);

}

though this can be done more easily use the event's currentTarget.

Translate
Community Expert ,
Dec 21, 2017 Dec 21, 2017

use:

this.couverture_out=rollout.bind(this,'couverture');

this.couverture.addEventListener("mouseout",this.couverture_out);

this.couverture.addEventListener("click", obj_bon.bind(this,'couverture'));

function obj_bon(obj) {

    this[obj].removeEventListener("mouseout", this[obj+"_out"]);

}

though this can be done more easily use the event's currentTarget.

Translate
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
Community Beginner ,
Dec 21, 2017 Dec 21, 2017

Thanks a lot,kglad, and i thinks i undestand better the way it's working know.

all the best

Gilles

Translate
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
Community Expert ,
Dec 21, 2017 Dec 21, 2017
LATEST

you're welcome.

Translate
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