Howard Jones wrote:
Having just made my first real piece of jQuery code, I'm already
wondering if it can be made more concise :-)
[ ... ]

$('input:[EMAIL PROTECTED]').each(
    function() {
         var myid = $(this).attr('name');
         $(this).parent().parent().click( function(event) {
             if(event.originalTarget.tagName != 'INPUT')
             {
                 var cb = $('input:[EMAIL PROTECTED]'+myid+']');
                 cb.attr('checked', !cb.attr('checked'));
                 return false;
             }
        });
    });

I'm still pretty new to JQuery as well, but one suggestion springs to mind. The call to

    $(this).parent().parent().//

looks rather brittle. If you ended up throwing a span or a label around the checkbox, this would break. It might be cleaner to do something like:

    $(this).parents("tr:first").//

You could skip the ":first" if you are quite certain that it won't be in a nested table situation...

Other than that, the code looks good to my newbie eyes.

  -- Scott

Reply via email to