Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So after playing with your code, here's the conclusion I've come to.</p> <p>It looks like the draggable jqueryui method is tracking its objects seperately. When you clone, that tracking isn't cloned. I modified your code as follows:</p> <pre><code>jQuery.fn.swapWith = function(to) { return this.each(function() { var copy_to = $(to).clone(true).appendTo($("#wrapper")); var copy_from = $(this).clone(true).appendTo($("#wrapper")); //$(to).replaceWith(copy_from); //$(this).replaceWith(copy_to); }); }; </code></pre> <p>You can see the fascinating results <a href="http://jsfiddle.net/XkUDv/16/" rel="nofollow">http://jsfiddle.net/XkUDv/16/</a></p> <p>As you can see, if you drag the new cloned objects, it moves the original, not the cloned one.</p> <p>It's not an answer, but I hope it helps.</p> <p>UPDATE:</p> <p>after taking a closer look at clone I changed the javascript to:</p> <pre><code>&lt;script type="text/javascript"&gt; jQuery.fn.swapWith = function(to) { return this.each(function() { var copy_to = $(to).clone(); var copy_from = $(this).clone(); $(to).replaceWith(copy_from); $(this).replaceWith(copy_to); }); }; $(document).ready(function() { options = { revert: true }; $("li").draggable(options); $('#wrapper').droppable({ drop: function(event, ui) { window.setTimeout(function(){ $('#one').swapWith($('#two')); $("li").draggable(options); }, 600); } }); }); &lt;/script&gt; </code></pre> <p>Now it works the way you wanted :)</p> <p>I'm guessing the issue is that since clone(true) copies the event handlers, when you try to reattach the draggable to the new clones it sees the old event handlers and ignores the elements. So instead of clone(true), I changed it to clone();</p> <p>hope that helps!</p> <p>Working version: <a href="http://jsfiddle.net/XkUDv/21/" rel="nofollow">http://jsfiddle.net/XkUDv/21/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload