Hi!

I am making a simple expanding list with categories and content.


This is my script:
this.OpenElement = function () {
        $(this).unbind('click', OpenElement);
        $(this).bind('click', CloseElement);
        $(this).parent("li").css({backgroundColor:
"#00ff00"}).children("ul").show();
        return false;
};
this.CloseElement = function () {
        $(this).unbind('click', CloseElement);
        $(this).bind('click', OpenElement);
        $(this).parent("li").css({backgroundColor:
"#ff0000"}).children("ul").hide();
        return false;
};
this.OpenAll = function () {
        $("a.Category").each(function () {
                $(this).unbind('click', OpenElement);
                $(this).bind('click', CloseElement);
                $(this).parent("li").css({backgroundColor:
"#00ff00"}).children("ul").show();
        });
        return false;
};
this.CloseAll = function () {
        $("a.Category").each(function () {
                $(this).unbind('click', CloseElement);
                $(this).bind('click', OpenElement);
                $(this).parent("li").css({backgroundColor:
"#ff0000"}).children("ul").hide();
        });
        return false;
};
$(document).ready(function() {
        $("ul ul").hide();
        $("a.Category").bind('click', OpenElement);
        $("a#ExpandAll").bind('click', OpenAll);
        $("a#CollapseAll").bind('click', CloseAll);
});


As you can see I do the same thing in the each() in CloseAll as I do
in CloseElement.
I thought that I could write like this:
        $("a.Category").each(OpenElement);

But that isn't working.

Maybe someone can help me and maybe someone has some input on the code
in it's whole because I am fairly new to jQuery.

Reply via email to