Best way to remove event specific event handlers in jQuery
<p>So, here is the situation.  I have several objects of the same type that are all listening to the same event.  The handlers of each of these objects manipulate some part of the DOM.  These objects can be recreated or destroyed at almost any time, when they are destroyed they take the part of the DOM they are responsible for with them.  The problem is that handlers for these objects stick around and continue to try to manipulate the DOM after the objects have been destroyed. </p>

<p>Below is the code that I have that seems to work.  However I do not care for the way the handlers are destroyed and I suspect it may not be good for jQuery.  Is there a better way?</p>

<pre><code>        var ID: "uniqueID",
    connectEvents: function ()
    {
      $(someDiv).on("customEvent", this, this.eventHandler);
    },
    eventHandler: function (e)
    {
        //do some stuff to the DOM
    },
    destroy: function ()
    {
      var gridCell = this;
      if (jQuery(someDiv).data("events"))
      {
         var handlers = jQuery(someDiv).data("events").customEvent
         var handlerIndex = -1;
         $(handlers).each(function (i, handler)
         {
            if (handler.data.ID === ID)
               handlerIndex = i;
         });
         if (handlerIndex &gt; 0)
         {
            handlers.splice(handlerIndex, 1);
         }
      }
      //Destroy some Dom elements
    }
</code></pre>
