jQuery Drag And Drop Using Live Events

Wojtek’s solution worked perfectly for me. I wound up changing it a tad bit to make it extend jQuery…

(function ($) {
   $.fn.liveDraggable = function (opts) {
      this.live("mouseover", function() {
         if (!$(this).data("init")) {
            $(this).data("init", true).draggable(opts);
         }
      });
      return this;
   };
}(jQuery));

Now instead of calling it like:

$(selector).draggable({opts});

…just use:

$(selector).liveDraggable({opts})

Leave a Comment