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.
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'));
}
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Elem TR, 'mouseleave', function () { that.Leave(); });
if I comment it out and
console.log(this.ElemTR);
it shows up..
$('#jqAOITab').on('click',
var c = new IPImpactControl($(this));
});
its the line that throws.
addEventListener(this.Elem
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/
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
$(this).on("mouseleave", ".child", function(event) {
// do something
});