javascript - Jquery clone method to clone mutliple (more than one) div's (not a single div multiple times) inside a page -
i need method clone 4 div's id's d_1, d_2, d_3, d_4 including contents inside each div @ once , detach divs, , need find copy of d_1 , contents clone , append again page.
something like:
var cloned=$('[id^="d_"]').clone(); $('[id^="d_"]').detach();
and find div id =d_1
clone , append body.
is possible?
use document fragment.
var $documentfragment = $(document.createdocumentfragment()); $('[id^="d_"]').each(function(){ $documentfragment.append($(this).clone().addclass("_cloned")); }); $documentfragment.clone().appendto(document.body);
if want looking element fragment, can this:
$(document.body).find("#d_1._cloned"). ... ;
if want remove element , append first copied fragment:
$("._cloned", document.body).remove(); $documentfragment.find("#d_1").clone().appendto(document.body);
Comments
Post a Comment