Reputation: 33
I have:
$(document).ready(function () {
$(".div1, .div2, .div3, .div4, .div5").draggable();
$("#menu").click(function () {
$("<div class='div1'></div>").appendTo("#layout");
});
});
But the draggable function works just to the divs that already exist when the page is loaded. When I add dynamically, I could not drag them.
My Html:
<div id="layout">
<div class="div1"></div>
</div>
Upvotes: 2
Views: 1417
Reputation: 10219
You just need to add the draggable handler to your new div with :
$("<div class='div1'></div>").appendTo("#layout").draggable();
for example.
Upvotes: 4
Reputation: 630379
In your case the easiest solution is to call .draggable()
on the new elements as you create them, like this:
$("<div class='div1'></div>").appendTo("#layout").draggable();
Upvotes: 2