Javascript examples for DOM:Document createDocumentFragment
The createDocumentFragment() method creates a Node object.
None
A DocumentFragment object, representing the created DocumentFragment node
The following code shows how to Create a documentFragment node and append a child to a list item.
<!DOCTYPE html> <html> <body> <ul><li>A</li><li>B</li></ul> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from w ww .j av a 2s . c om*/ var d = document.createDocumentFragment(); d.appendChild(document.getElementsByTagName("LI")[0]); d.childNodes[0].childNodes[0].nodeValue = "New"; document.getElementsByTagName("UL")[0].appendChild(d); } </script> </body> </html>