the murmurous sea

[HTML DOM] DocumentFragment 본문

#dev/개념정리

[HTML DOM] DocumentFragment

lunacer 2020. 5. 2. 12:48

1. a minimal document object that has no parent.
2. used as a lightweight version of Document that stores a segment of a document structure comprised of nodes just like a standard document.
3. The key difference is due to the fact that the document fragment isn't part of the active document tree structure.
4. Changes made to the fragment don't affect the document (even on reflow) or incur any performance impact when changes are made.
5. No specific Properties, Methods
   : inherits properties and methods of its parent, Node, and implements those of the ParentNode interface.
6. An empty DocumentFragment can be created using the document.createDocumentFragment() method or the constructor.

 

[Constructor]

DocumentFragment()

 

[document.createDocumentFragment()]


: creates an imaginary Node object, with all the properties and methods of the Node object.
: useful when you want to extract parts of your document / change, add, or delete, some of the content and insert it back to your document. You can also use the document's Document object to perform these changes, but to prevent destroying the document structure, it can be safer to extract only parts of the document, make the changes, and insert the part back to the document.

[Common Use]

: to create one, assemble a DOM subtree within it, then append or insert the fragment into the DOM. 
: moves the fragment's nodes into the DOM, leaving behind an empty DocumentFragment. Because all of the nodes are inserted into the document at once, only one reflow and render is triggered instead of potentially one for each node inserted if they were inserted separately.

 


https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment

https://www.w3schools.com/jsref/met_document_createdocumentfragment.asp

https://umbum.dev/207

Comments