HTML::O...Fragment(3)
π HTML::Object::DOM::DocumentFragment β the HTML Object DOM Document Fragment Class
okay so bestie, welcome to HTML::Object::DOM::DocumentFragment, aka the HTML Object DOM Document Fragment Class π like yes that's the whole name, we don't do short names here, iykyk.
This is basically a lil mini-document that has no parent and lives its best independent life. she's giving main character energy but also she's not in the tree. iconic.
β¨ 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 );
and that would yield, bestie:
- Apple
- Orange
- Banana
- Melon
periodt. π build it in the fragment, then yeet the whole thing into the list. that's the whole vibe.
π VERSION π
v0.2.0
π DESCRIPTION π
okay so this implements the interface for document fragments, which is β direct quote energy β a minimal document object that has no parent β¨.
it gets used as a lightweight version of Document that stores a segment of a document structure comprised of nodes, just like a standard document. and the key difference? the way that the document fragment is not part of the active document tree structure. like she's off doing her own thing π¦.
changes made to the fragment do not affect the document (even on reflow) and do not incur any performance impact when changes are made. no cap, that's the whole point. go off, fragment. π
it inherits from HTML::Object::DOM::Node, tyvm.
π§ INHERITANCE π§
look at this lil family tree, the way it's laid out is literally art π¨:
+-----------------------+ +---------------------------+ +-------------------------+ +-------------------------------------+
| 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. just a number. a count. she's counting her kids (the elements).
children
Read-only π
returns an array object containing all objects of type Element that are children of the DocumentFragment object. yes, an actual array object. thank you Module::Generic::Array vibes.
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 β and that's literally where the page cuts off π bestie the manpage just trails off mid-sentence, but you already know what it means: undef when there isn't one. π
πΈ CONSTRUCTOR πΈ
new
Instantiates and returns a new DocumentFragment object. brand new baby fragment, fresh out the box πβ¨
π METHODS π
this interface inherits the methods of its parent Node and implements the following ones, bestie β here's the full lineup, no skips:
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. so like, stringified children. all of them. together. π₯
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.
three for three on the undefs β she has no parent, remember? that's literally her whole brand π
no parents, no problems.
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. yes it returns an array object β plural energy π«Ά
replaceChildren
Replaces the existing children of a DocumentFragment with a specified new set of children. out with the old, in with the new πβ‘οΈβ¨
π AUTHOR π
Jacques Deguest <jack@deguest.jp>
β SEE ALSO β
HTML::Object::DocumentHTML::Object::ElementHTML::Object::Node- Mozilla documentation β
https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragmentπ
π 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.
and that's the whole page, bestie π«Ά you ate that. go build your fragment, append it, and slay β¨
this page was brought to you by perl v5.42.2, dated 2026-02-15 β mwah, ily, see you in the next manpage π
π¦ where this page comes from
- alpine 3.24: perl-html-object-doc 0.6.0-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms