Avatar of skillilea
skillilea asked on

Javascript attach events through an object

I am trying to dynamically create events through a user clicking on the row.


I load the click function in jQuery like this:

I keep getting an error that the element passed is not an object.

Is there a better way to create these events?

Do I use attachEvent or addEventListener??

thanks tons for the help.



    $('#jqAOITab').on('click', 'tr:gt(1)', function () {
        var c = new IPImpactControl($(this));
    });




function IPImpactControl(elem) {
    this.ElemTR = elem;
    this.attachEvents();
}


IPImpactControl.prototype = {

    attachEvents: function () {
        var that = this;
        [b]addEventListener(this.ElemTR, 'mouseleave', function () { that.Leave(); });
[/b]        console.log(this.ElemTR);
    },

    Leave: function () {
        var that = this;
        console.log('leave');
        //that.one(console.log('leave'));
    }



};

Open in new window

jQueryJavaScript

Avatar of undefined
Last Comment
Rob

8/22/2022 - Mon
leakim971

Why do you attach element with simple javascript instead jQuery?

$(this).on("mouseleave", ".child", function(event) {
    // do something
});
ASKER CERTIFIED SOLUTION
Rob

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
skillilea

I do get the TR object when doing this

    $('#jqAOITab').on('click', 'tr:gt(1)', function () {
        var c = new IPImpactControl($(this));
    });


its the line that throws.
 addEventListener(this.ElemTR, 'mouseleave', function () { that.Leave(); });

if I comment it out and
console.log(this.ElemTR);

it shows up..
leakim971

What is the purpose of all of this?
Could answer my previous question?
Could you provide a simple link to see that in live?
http://jsfiddle.net/
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Rob

Why are you trying to use addEventListener? You're using jQuery so use it as leakim971 has indicated in his first post