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

skillileaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Why do you attach element with simple javascript instead jQuery?

$(this).on("mouseleave", ".child", function(event) {
    // do something
});
0
RobOwner (Aidellio)Commented:
Do either of these still give you the error?
$('#jqAOITab tr:gt(1)').on('click', function () {
        var c = new IPImpactControl($(this));
    });

Open in new window


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

Open in new window


looking at the api, when you supply 3 arguments, it may be looking for an object as the first argument:  http://api.jquery.com/on/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skillileaAuthor Commented:
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..
0
leakim971PluritechnicianCommented:
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/
0
RobOwner (Aidellio)Commented:
Why are you trying to use addEventListener? You're using jQuery so use it as leakim971 has indicated in his first post
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.