HTML DOM createDocumentFragment () method
Examples
Create a documentFragment node:
var d=document.createDocumentFragment();
d.appendChild(document.getElementsByTagName("LI")[0]);
d.childNodes[0].childNodes[0].nodeValue="Milk";
document.getElementsByTagName("UL")[0].appendChild(d);
d.appendChild(document.getElementsByTagName("LI")[0]);
d.childNodes[0].childNodes[0].nodeValue="Milk";
document.getElementsByTagName("UL")[0].appendChild(d);
Output:
before fixing:
- Coffee
- Tea
Modified:
- Tea
- Milk
try it"
Definition and Usage
createdocumentfragment () method creates a virtual node object, the node object contains all the properties and methods.
When you want to extract part of the document, change, add, or delete content and documents can be inserted at the end createDocumentFragment () method.
You can also use the document object document to implement these changes, but to prevent the file structure is destroyed, createDocumentFragment () method may be safer to change the structure of the nodes in the document.
Browser Support
All major browsers support createDocumentFragment () method
grammar
document.createDocumentFragment()
parameter
None.
return value
类型 | 描述 |
---|---|
DocumentFragment 对象 | 创建文档片段对象 |
technical details
DOM version | Core Level 1 Document Object |
---|