How to append div with div's inside using jquery?
I have a div with all kinds of div's inside. If i append them only the first one is draggable. Do i have to use append parent for开发者_StackOverflow this or something else?
Here is a jsfiddle of my problem;
http://jsfiddle.net/nNzkr/
You have multiple div
s with the same id. That's invalid HTML.
Also note that you're appending your new div
elements to the one that handles the click
event and creates new ones.
You'll have to call .draggable(...)
on each div as they are created.
Here is your example with each element draggable.
http://jsfiddle.net/nNzkr/1/
$("#duplicate").click(function() {
var html = $(elem);
$("#wrap").append(html);
html.draggable({});
});
$('.draggable').draggable({});
var elem = '<div class="draggable"><div></div></div>';
精彩评论