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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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..
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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/
Avatar of Rob
Rob
Flag of Australia image

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

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo