Using appendTo multiple time slows down Performance

42 Views Asked by At
function pp(){
$(document).xpath("//*[@id='Form1']/div[3]/div[1]/img").attr("src","http://i.imgur.com/uo5RuFX.png").clone().appendTo("body");
   $("#BreadCrumb_pnlResults").clone().appendTo("body");




      }

I want to execute the above code multiple time but with each execution the performance slows down to point where the script becomes unresponsive. Is there is any better way to execute the above code. I heard about

createDocumentFragment();

but I don't know how to use it in my code Please help

1

There are 1 best solutions below

0
Fawaz Ahmed On

Now it's working i used this

function pp(){
frag = document.createDocumentFragment();
var body = document.body;
var kp =   document.getElementById("IDName").cloneNode(true);
var ppma = frag.appendChild(kp);
body.appendChild(ppma);
}