> var toggleContent = {
> cel : null,
> doIt : function (el)
> {
> if (this.cel) {
> $('#' + this.cel).slideUp('slow');
> }
> if (el != this.cel) {
> this.cel = el;
> $('#' + this.cel).slideDown('slow', function(cel){
> alert(this.cel); $('#h_' + this.cel).ScrollTo(1500); });
> } else {
> this.cel = null;
> }
> return false;
> }
>
> }
>
> in the line: " $('#' + this.cel).slideDown('slow',
> function(cel){ alert(this.cel); $('#h_' +
> this.cel).ScrollTo(1500); }); " : how could access the
> var this.cel?
>
> when im trying of access this var i get the "undefined"
> value.. i think this is happend because the function is
> inside of the another function.. how could access a variable
> if this is outside of the parent function? exist something
> like this? "_parent.var" ?
Take advantage of lexical scoping and save a reference to "this" in the
parent. The code below uses "self", but there's nothing special about that
particular name:
var toggleContent = {
cel : null,
doIt : function (el)
{
var self = this;
if (self.cel) {
$('#' + self.cel).slideUp('slow');
}
if (el != self.cel) {
self.cel = el;
$('#' + self.cel).slideDown('slow', function(cel){ alert(self.cel);
$('#h_' + self.cel).ScrollTo(1500); });
} else {
self.cel = null;
}
return false;
}
}
-Mike
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/