I play with document fragment . It's hard for me to understand how it behaves when I add it to the DOM.
I create a doc fragment that I assign to a variable when I insert some things into it, and add a document fragment to the element. But if I clear the element my variable, which should refer to a document fragment, it contains an empty document fragment.
I am trying to make a cache for a third-party library that creates document fragments. So I would like this to work. Should I create a cloneNode before adding a fragment to the DOM, right?
I created a JS script: http://jsfiddle.net/4CTXG/1/
var test = document.createDocumentFragment(); //var test = document.createElement("div"); // This one work $(test).append($("<div>").html('Hello world!')); $("#result").append(test); setTimeout(function(){ $("#result").children().remove(); $("#result").append(test); console.log('Now test should have been appended'); $(result).css({"background": "#FF0000"}); },5000)
source share