Link to home
Start Free TrialLog in
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

Avatar of leakim971
leakim971
Flag of Guadeloupe image

Why do you attach element with simple javascript instead jQuery?

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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skillilea
skillilea

ASKER

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..
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/
Why are you trying to use addEventListener? You're using jQuery so use it as leakim971 has indicated in his first post