So I have this code:
function theObject(){
this.someelement = $("#someelement");
this.someotherelement = $("someotherelement");
this.someelement.fadeOut(500, function(){
this.someotherelement.attr("title", "something");
this.someelement.fadeIn(500);
});
}
for some reason this.someotherelement is undefined. I’m guessing because it’s wrapped in a function(){}?
This is caused by a JavaScript scoping issue. Creating a function creates a new scope for
thiswhich makesthisrefer to the function. You can fix it by doing … this: