Hello,

This question is not actually related with Gadget Development directly
although I'm using this code for a new gadget. It's rather JavaScript
related. I've asked the same question in other groups/forums as well
but haven't got any answers. So I'm trying my chances with my fellow
Gadget Developers.

I have written this jQuery code and manage to make it work:

$('#item1').click(function() {
        if ($("#tabcontent1").is(":hidden")) {
                if(active == "init") {
                        $("#tabcontent1").slideDown(300);
                        active = "#tabcontent1";
                } else {
                        $(active).slideUp(300, function() {
                                $("#tabncontent1").slideDown(300);
                                active = "#tabcontent1";
                        });
                }
        } else {
                $("#tabcontent1").slideUp(300);
        }

}

The problem has arisen after I decided to create a single for loop
instead of binding all elements one by one. Although I managed to get
it work with some workaround I'm not happy with the result:

for(var i = 1; i < 6;i ++) {
        item = '#item'+i;
        $(item).click(function() {
                alert(vts(this));
                if ($(vts(this)).is(":hidden")) {
                        if(active == "init") {
                                $(vts(this)).slideDown(300);
                                active = vts(this);
                        } else {
                                that = vts(this);
                                $(active).slideUp(300, function() {
                                        $(that).slideDown(300);
                                        active = that;
                                });
                        }
                } else {
                        $(vts(this)).slideUp(300);
                        active = 'init';
                }
        });

}

function vts(e) {
        var t;
        t = e.id;
        t = t.replace(/item/ig, '');
        t = '#tabcontent'+t;
        return t;

}

what I really want is creating some kind of code like this:

for(var i = 1; i < 6; i++) {

var item = '#item'+i;
var element = '#tabcontent'+i;
$(item).click(function() {
        if ($(element).is(":hidden")) {
                if(active == "init") {
                        $(element).slideDown(300);
                        active = element;
                } else {
                        $(active).slideUp(300, function() {
                                $(element).slideDown(300);
                                active = element;
                        });
                }
        } else {
                $(element).slideUp(300);
        }

}
}

The problem with the above code is the $(element) stays as the last
assigned value (#tabcontent5). I need to find a way to register that
element
variable as a static value instead of the variable itself.

Any help would be appreciated.

Ozberk
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"iGoogle Developer Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Gadgets-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to