[jQuery] How to bind a function only once

[jQuery] How to bind a function only once


> I have a group of checkboxes, and as long as any one of
> the boxes is checked I need a function bound to a select
> list, but anytime none of the boxes are checked I need the
> function unbound. What I have below binds and unbinds,
> but if I select lets say 4 checkboxes the function is bound
> and called 4 times when I change my select list. How do
> I just bind it once?
>
> $('input[@name=label_checkbox]').click(function(){
>         if($("input[@name='label_checkbox']").is(":checked")) {
>             $('#label').bind('change', function(){
>                 alert('test');
>             });
>         } else {
>             $('#label').unbind('change');
>         }
>     });
I would bind the event once, then look at the check boxes when the event
occurs.
$('#label').bind('change', function(){
    if($("input[@name='label_checkbox']").is(":checked")) {
        alert('test');
    }
});
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/