Making an element draggable?

Posted by user246114 on Stack Overflow See other posts from Stack Overflow or by user246114
Published on 2010-06-13T16:57:46Z Indexed on 2010/06/13 17:02 UTC
Read the original article Hit count: 138

Filed under:

Hi,

I'm trying to make an element draggable, like so:

var element = $("<li id='test'>Hello</li>");
element.appendTo("#panelParent");
element.draggable("enable");
element.draggable("option", "connectToSortable", '#panelTarget');
element.draggable("option", "helper", 'clone');
element.draggable("option", "revert", 'invalid');

nothing happens when I try dragging this element. It works fine though if I embed the object in the page beforehand instead of trying to dynamically create the element. Any idea what I'm missing? For example, this works:

$(function() {
    $("#test").draggable({
        connectToSortable: '#panelTarget',
        helper: 'clone',
        revert: 'invalid'
     });
});

<ul>
  <li id='test'>Hello</li>
</ul>

Thanks

© Stack Overflow or respective owner

Related posts about jquery-ui