Jquery $().each method obscures 'this' keyword
Posted
by Jeff Fritz
on Stack Overflow
See other posts from Stack Overflow
or by Jeff Fritz
Published on 2009-06-11T12:32:13Z
Indexed on
2010/04/19
8:33 UTC
Read the original article
Hit count: 294
JavaScript
|jQuery
I am creating a Javascript object that contains a function that executes a jQuery each
method like the following:
function MyClass {
Method1 = function(obj) {
// Does something here
}
Method2 = function() {
$(".SomeClass").each(function() {
// 1 2
this.Method1(this);
});
}
}
Which object is each THIS
referring to? jQuery is referring to the item returned from the each
iteration. However, I would like This[1]
to refer to the containing class...
How can I refer to the containing class from within the jQuery loop?
© Stack Overflow or respective owner