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 typeNode
that are children of theDocumentFragment
object. ParentNode.firstElementChild
(en-US) Somente leitura Experimental-
Returns the
Element
that is the first child of theDocumentFragment
object, ornull
if there is none. ParentNode.lastElementChild
(en-US) Somente leitura Experimental-
Returns the
Element
that is the last child of theDocumentFragment
object, ornull
if there is none. ParentNode.childElementCount
Somente leitura Experimental-
Returns an
unsigned long
giving the amount of children that theDocumentFragment
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 theDocumentFragment
. DocumentFragment.findAll()
Experimental-
Returns a
NodeList
of matchingElement
in the tree of theDocumentFragment
. DocumentFragment.querySelector()
(en-US)-
Returns the first
Element
node within theDocumentFragment
, in document order, that matches the specified selectors. DocumentFragment.querySelectorAll()
(en-US)-
Returns a
NodeList
of all theElement
nodes within theDocumentFragment
that match the specified selectors. DocumentFragment.getElementById()
(en-US)-
Returns the first
Element
node within theDocumentFragment
, in document order, that matches the specified ID.
Especificações
Specification | Status | Comment |
---|---|---|
DOM The definition of 'DocumentFragment' in that specification. |
Padrão em tempo real | Added the constructor and the implementation of ParentNode . |
Selectors API Level 2 The definition of 'DocumentFragment' in that specification. |
Obsoleto | Added the find() and findAll() methods. |
Selectors API Level 1 The definition of 'DocumentFragment' in that specification. |
Obsoleto | Added the querySelector() and querySelectorAll() methods. |
Document Object Model (DOM) Level 3 Core Specification The definition of 'DocumentFragment' in that specification. |
Obsoleto | No change from Document Object Model (DOM) Level 2 Core Specification |
Document Object Model (DOM) Level 2 Core Specification The definition of 'DocumentFragment' in that specification. |
Obsoleto | No change from Document Object Model (DOM) Level 1 Specification |
Document Object Model (DOM) Level 1 Specification The definition of 'DocumentFragment' in that specification. |
Obsoleto | Initial definition |
Compatibilidade com navegadores
BCD tables only load in the browser