Why does a jquery clone clone a parent, but not his children?
I have a parent div with its child layer:
<div id="padre" class="demo">
<ul id="sortable1" class="droptrue ui-sortable">
<li id="app1" class="ui-state-default toolTip">
<div id="00" class="AppPadre"></div>
So, when I clone my parent div with the following line:
var $copia = $('#padre>*').clone();
and I print my cloned variable that only shows:
<div id="padre" class="demo">
<ul id="sortable1" class="droptrue ui-sortable">
Does anyone know why it only copies level 1? Thanks in advance. Immediately after the copy, I delete all sub-items of "padre" with $ ('# padre> *'). Remove (); and it removes all subelements, but when I add it, it adds only the 1st padre subelement.
+3
2 answers
You did not close the tags correctly:
<div id="padre" class="demo">
<ul id="sortable1" class="droptrue ui-sortable">
<li id="app1" class="ui-state-default toolTip"><li>
</ul>
<div id="00" class="AppPadre"></div>
</div>
Edit: Try the following:
$('#padre').children().clone();
$("#clone").append($copia);
$('#padre').remove();
+4