NAME
HTML::Object::DOM::DocumentFragment - HTML Object DOM Document Fragment Class
SYNOPSIS
use HTML::Object::DOM::DocumentFragment;
my $frag = HTML::Object::DOM::DocumentFragment->new ||
die( HTML::Object::DOM::DocumentFragment->error, "\n" );
<ul id="list"></ul>
use Module::Generic::Array;
my $list = $doc->querySelector('#list')
my $fruits = Module::Generic::Array->new( [qw( Apple Orange Banana Melon )] );
my $fragment = HTML::Object::DOM::DocumentFragment->new;
# or
my $fragment = $doc->createDocumentFragment();
$fruits->foreach(sub
{
my $fruit = shift( @_ );
my $li = $doc->createElement('li');
$li->innerHTML = $fruit;
$fragment->appendChild( $li );
})
$list->appendChild( $fragment );
would yield:
Apple
Orange
Banana
Melon
VERSION
v0.2.0
DESCRIPTION
This implements the interface for document fragments, which is a minimal document object that has no parent.
It is used as a lightweight version of Document that stores a segment of a document structure comprised of nodes just like a standard document. The key difference is due to the fact that the document fragment is not part of the active document tree structure. Changes made to the fragment do not affect the document (even on reflow) or incur any performance impact when changes are made.
It inherits from HTML::Object::DOM::Node
INHERITANCE
+-----------------------+ +---------------------------+ +-------------------------+ +-------------------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::DocumentFragment |
+-----------------------+ +---------------------------+ +-------------------------+ +-------------------------------------+
PROPERTIES
childElementCount
Read-only
Returns the amount of child elements the DocumentFragment has.
children
Read-only
Returns an array object containing all objects of type Element that are children of the DocumentFragment object.
firstElementChild
Read-only
Returns the Element that is the first child of the DocumentFragment object, or undef
if there is none.
lastElementChild
Read-only
Returns the Element that is the last child of the DocumentFragment object, or undef
if there is
CONSTRUCTOR
new
Instantiates returns a new DocumentFragment object.
METHODS
This interface inherits the methods of its parent Node and implements the following ones:
append
Inserts a set of Node objects or HTML string after the last child of the document fragment.
as_string
Returns a string representation of all the children contained.
getElementById
Returns the first Element node within the DocumentFragment, in document order, that matches the specified ID. Functionally equivalent to getElementById().
parent
Returns always undef
parentElement
Returns always undef
parentNode
Returns always undef
prepend
Inserts a set of Node objects or HTML string before the first child of the document fragment.
querySelector
Returns the first Element node within the DocumentFragment, in document order, that matches the specified selectors.
querySelectorAll
Returns a array object of all the Element nodes within the DocumentFragment that match the specified selectors.
replaceChildren
Replaces the existing children of a DocumentFragment with a specified new set of children.
AUTHOR
Jacques Deguest <jack@deguest.jp>
SEE ALSO
HTML::Object::Document, HTML::Object::Element, HTML::Object::Node
COPYRIGHT & LICENSE
Copyright(c) 2021 DEGUEST Pte. Ltd.
All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.