tags:

views:

13

answers:

2

how to drag dynamically created elements?

A: 

Once you've created the element, use any of the various jQuery mechanisms for getting a jquery object for it (for instance, if it has an id, use $('#theId')), and call draggable on it:

$("#someId").draggable();

Live example: http://jsbin.com/iqori3

Relevant JavaScript:

// Create a div
var div = $("<div style='border: 1px solid; background-color: #eee; width: 100px'>I'm dynamic</div>");
div.appendTo(document.body);

// Make it draggable
div.draggable();
T.J. Crowder
A: 

Have you applied the .draggable() on them as you dynamically create them?

// Create a new div element with the something class that is draggable.
$("body").append("<div />").addClass("something").draggable();
mkoistinen