DocumentFragment
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since julho de 2015.
* Some parts of this feature may have varying levels of support.
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 deles.
Um DocumentFragment pode ser criado usando o método document.createDocumentFragment 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.childrenSomente leitura Experimental-
Returns a live
HTMLCollectioncontaining all objects of typeNodethat are children of theDocumentFragmentobject. ParentNode.firstElementChildSomente leitura Experimental-
Returns the
Elementthat is the first child of theDocumentFragmentobject, ornullif there is none. ParentNode.lastElementChildSomente leitura Experimental-
Returns the
Elementthat is the last child of theDocumentFragmentobject, ornullif there is none. ParentNode.childElementCountSomente leitura Experimental-
Returns an
unsigned longgiving the amount of children that theDocumentFragmenthas.
Construtor
DocumentFragment()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
Elementin the tree of theDocumentFragment. DocumentFragment.findAll()Experimental-
Returns a
NodeListof matchingElementin the tree of theDocumentFragment. DocumentFragment.querySelector()-
Returns the first
Elementnode within theDocumentFragment, in document order, that matches the specified selectors. DocumentFragment.querySelectorAll()-
Returns a
NodeListof all theElementnodes within theDocumentFragmentthat match the specified selectors. DocumentFragment.getElementById()-
Returns the first
Elementnode within theDocumentFragment, in document order, that matches the specified ID.
Especificações
| Specification |
|---|
| DOM> # interface-documentfragment> |
Compatibilidade com navegadores
Loading…