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
2010-09-20 10:22:18
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
2010-09-20 10:24:39