Skip to main content
Participating Frequently
December 21, 2017
Answered

Dynamic naming

  • December 21, 2017
  • 1 reply
  • 215 views

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

    This topic has been closed for replies.
    Correct answer kglad

    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.

    1 reply

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    December 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.

    Gico62Author
    Participating Frequently
    December 21, 2017

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

    all the best

    Gilles

    kglad
    Community Expert
    Community Expert
    December 21, 2017

    you're welcome.