DocumentFragment

A interface do DocumentFragment representa um objeto de documento mínimo que não possui pai. Ela é utilizada como uma versão leve de Document para armazenar fragmentos bem formados ou fragments potencialmente mal formados de XML.

Vários outros métodos podem usar um document fragment como argumento (ex. qualquer interface de Node como Node.appendChild e Node.insertBefore) em casos em que os filhos do fragment são acrescentados ou inseridos, e não o próprio fragment.

Essa interface também é excelente para ser usada com Web components: elementos <template> contém um DocumentFragment na propriedade HTMLTemplateElement.content (en-US) deles.

Um DocumentFragment pode ser criado usando o método document.createDocumentFragment (en-US) ou o construtor.

Propriedades

Essa interface não tem uma propriedade específica, mas herda de seu pai, Node, e implementa aquelas da interface ParentNode.

ParentNode.children (en-US) Somente leitura Experimental

Returns a live HTMLCollection containing all objects of type Node that are children of the DocumentFragment object.

ParentNode.firstElementChild (en-US) Somente leitura Experimental

Returns the Element that is the first child of the DocumentFragment object, or null if there is none.

ParentNode.lastElementChild (en-US) Somente leitura Experimental

Returns the Element that is the last child of the DocumentFragment object, or null if there is none.

ParentNode.childElementCount Somente leitura Experimental

Returns an unsigned long giving the amount of children that the DocumentFragment has.

Construtor

DocumentFragment() (en-US) Experimental

Retorna um objeto DocumentFragment vazio.

Métodos

This interface inherits the methods of its parent, Node, and implements those of the ParentNode interface.

DocumentFragment.find() Experimental

Returns the first matching Element in the tree of the DocumentFragment.

DocumentFragment.findAll() Experimental

Returns a NodeList of matching Element in the tree of the DocumentFragment.

DocumentFragment.querySelector() (en-US)

Returns the first Element node within the DocumentFragment, in document order, that matches the specified selectors.

DocumentFragment.querySelectorAll() (en-US)

Returns a NodeList of all the Element nodes within the DocumentFragment that match the specified selectors.

DocumentFragment.getElementById() (en-US)

Returns the first Element node within the DocumentFragment, in document order, that matches the specified ID.

Especificações

Specification
DOM Standard
# interface-documentfragment

Compatibilidade com navegadores

BCD tables only load in the browser

Veja também