I have a method in a class and into this method i have a handler for a click event in a div element:
function MyClass(container)
{
this.Container=container;
this.PrepareHandlers = function()
{
$('#Div1').click(function() {
alert(this.Container);
});
};
}
But since im into the handler, "this" is the clicked element. Is possible to access to a property of an object from a handler declared inside a method?
function MyClass(container)
{
var self = this;
this.Container=container;
this.PrepareHandlers = function()
{
$('#Div1').click(function() {
alert(self.Container);
});
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With