jQuery/javascript - Wire up event handler only when its not already assigned
<p>I'm assigning an onclick handler to a checkbox. Sometimes javascript that does the binding of event runs more than once (on partial postbacks) and the handler gets assigned twice. How can I prevent the handler from being assigned multiple times?  </p>

<p>Okay thanks for responses. I wrote something up to figure out if element has a hanlder:</p>

<pre><code>$.fn.hasHandler = function(eventName, handler)
{
    var _hasHandler = false;

    if(handler != undefined &amp;&amp; this.data("events") !== null &amp;&amp; this.data("events") !== undefined)
    {
        $.each(this.data("events"), function(name, handlers)
        {
            if(name === eventName)      
            {
                $.each(handlers, function(index, value)
                {
                    if(value.handler === handler)
                    {
                        _hasHandler = true;
                    }
                });
            }
        });
    }

    return _hasHandler;
}
</code></pre>
