HTML::Object::DOM::DocumentFragment - HTML Object DOM Document Fragment Class
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
v0.2.0
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
+-----------------------+ +---------------------------+ +-------------------------+ +-------------------------------------+ | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::DocumentFragment | +-----------------------+ +---------------------------+ +-------------------------+ +-------------------------------------+
Read-only
Returns the amount of child elements the DocumentFragment has.
Returns an array object containing all objects of type Element that are children of the DocumentFragment object.
Returns the Element that is the first child of the DocumentFragment object, or undef if there is none.
undef
Returns the Element that is the last child of the DocumentFragment object, or undef if there is
Instantiates returns a new DocumentFragment object.
This interface inherits the methods of its parent Node and implements the following ones:
Inserts a set of Node objects or HTML string after the last child of the document fragment.
Returns a string representation of all the children contained.
Returns the first Element node within the DocumentFragment, in document order, that matches the specified ID. Functionally equivalent to getElementById().
Returns always undef
Inserts a set of Node objects or HTML string before the first child of the document fragment.
Returns the first Element node within the DocumentFragment, in document order, that matches the specified selectors.
Returns a array object of all the Element nodes within the DocumentFragment that match the specified selectors.
Replaces the existing children of a DocumentFragment with a specified new set of children.
Jacques Deguest <jack@deguest.jp>
HTML::Object::Document, HTML::Object::Element, HTML::Object::Node
Mozilla documentation
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.
To install HTML::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Object
CPAN shell
perl -MCPAN -e shell install HTML::Object
For more information on module installation, please visit the detailed CPAN module installation guide.