documentfragment

Inserting arbitrary HTML into a DocumentFragment

不想你离开。 提交于 2019-11-27 06:24:49
I know that adding innerHTML to document fragments has been recently discussed, and will hopefully see inclusion in the DOM Standard. But, what is the workaround you're supposed to use in the meantime? That is, take var html = '<div>x</div><span>y</span>'; var frag = document.createDocumentFragment(); I want both the div and the span inside of frag , with an easy one-liner. Bonus points for no loops. jQuery is allowed, but I've already tried $(html).appendTo(frag) ; frag is still empty afterward. Here is a way in modern browsers without looping: var temp = document.createElement('template');

Does using a document fragment really improve performance?

♀尐吖头ヾ 提交于 2019-11-27 03:44:24
I've got a doubt regarding performance in JS. Say, I've got the next code: var divContainer = document.createElement("div"); divContainer.id="container"; var divHeader = document.createElement("div"); divHeader.id="header"; var divData = document.createElement("div"); divData.id="data"; var divFooter = document.createElement("div"); divFooter.id="footer"; divContainer.appendChild( divHeader ); divContainer.appendChild( divData ); divContainer.appendChild( divFooter ); document.getElementById("someElement").appendChild( divContainer ); This code just creates the shell for some other functions

Is there any way to find an element in a documentFragment?

左心房为你撑大大i 提交于 2019-11-26 16:43:03
问题 var oFra = document.createDocumentFragment(); // oFra.[add elements]; document.createElement("div").id="myId"; oFra.getElementById("myId"); //not in FF How can I get "myId" before attaching fragment to document? 回答1: What about: var oFra = document.createDocumentFragment(); var myDiv = document.createElement("div"); myDiv.id="myId"; oFra.appendChild(myDiv); oFra.getElementById("myId"); //not in FF Unless you've added the the created div to your document fragment I'm not sure why

Does using a document fragment really improve performance?

徘徊边缘 提交于 2019-11-26 12:42:09
问题 I\'ve got a doubt regarding performance in JS. Say, I\'ve got the next code: var divContainer = document.createElement(\"div\"); divContainer.id=\"container\"; var divHeader = document.createElement(\"div\"); divHeader.id=\"header\"; var divData = document.createElement(\"div\"); divData.id=\"data\"; var divFooter = document.createElement(\"div\"); divFooter.id=\"footer\"; divContainer.appendChild( divHeader ); divContainer.appendChild( divData ); divContainer.appendChild( divFooter );