Thanks, that makes sense. I still don't feel good about this code...

$.fn.disable = function() {
    $(this).attr("checked", false);
    $(this).attr("disabled", true);
    return $(this);
}

$.fn.enable = function() {
    $(this).attr("disabled", false);
    return $(this);
}

$(".responsibleCouncil .category").each(function() {
    var cat = $(this);
    var inputSelector = "ul input";

    cat.find(".toggler input").focus(function() {
        cat.siblings().find(inputSelector).disable();
        cat.find(inputSelector).enable();
    });
});


What do you think? Any obvious improvements? Corresponding Form
structure:

<form>
...
    <fieldset class="responsibleCouncil">
        ...
        <div class="category">
            <div class="toggler">
                <input type="radio" ... />
            </div>
            <ul>
                <li><input type="radio"... /></li>
                <li><input type="radio"... /></li>
            </ul>
        </div>
        ...repeated
    </fieldset>
    ...
</form>

Thomas

On Dec 3, 1:19 pm, "Josh Nathanson" <[EMAIL PROTECTED]> wrote:
> You have to do it that way because the context has changed.  Thus "this" in
> the second anonymous function will refer to something different than in the
> first.  A lot of people use the convention "var self = this" or something
> similar.
>
> Also within the anonymous function you can do this:
> siblings.find( etc );
> category.find( etc );
>
> ...since they are already jQuery objects.
>
> -- Josh
>
> -----Original Message-----
> From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
>
> Behalf Of 703designs
> Sent: Wednesday, December 03, 2008 9:44 AM
> To: jQuery (English)
> Subject: [jQuery] Scope variables in anonymous functions?
>
> What I'm trying to figure out is how I can access parent scopes from a
> nested anonymous function. As you can see here, I'm managing to do
> this by assigning "this" to variables, but I know that there's a way
> to pass "this" into the anonymous functions:
>
> $(".responsibleCouncil .category").each(function() {
>     var category = $(this);
>     var input = $(this).find(".toggler input");
>     var siblings = $(this).siblings();
>
>     input.click(function() {
>         $(siblings).find("ul").hide();
>         $(category).find("ul").show();
>     });
> });
>
> Basically, those three assignments at the top of the first anonymous
> function would be unnecessary if I knew of a better way to access
> "this" from nested functions.
>
>

Reply via email to