HTML::O...NodeList(3)
okay so bestie, welcome to the HTML::Object::DOM::NodeList (3) page β yes, the header shortens it to HTML::O...NodeList(3), and yes, it's User Contributed Perl Documentation. It's giving node-collection main character energy, and I'm obsessed π
β¨
πΈ NAME πΈ
HTML::Object::DOM::NodeList β HTML Object DOM NodeList Class
β¨ SYNOPSIS β¨
use HTML::Object::DOM::NodeList;
my $list = HTML::Object::DOM::NodeList->new ||
die( HTML::Object::DOM::NodeList->error, "\n" );
π VERSION π
v0.2.0
π DESCRIPTION π
NodeList objects are collections of nodes. You'll usually get one back from properties like childNodes in HTML::Object::DOM::Node and methods like querySelectorAll in HTML::Object::DOM::Document. That's the whole vibe, no cap π¦
π₯ PROPERTIES π₯
π length π
length is literally the number of nodes in the NodeList, periodt π
Example:
# All the paragraphs in the document
my $items = $doc->getElementsByTagName("p");
# For each item in the list,
# append the entire element as a string of HTML
my $gross = "";
for( my $i = 0; $i < $items->length; $i++ )
{
$gross += $items->[$i]->innerHTML;
}
# $gross is now all the HTML for the paragraphs
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/length
π METHODS π
It inherits methods from its parent Module::Generic::Array β iconic behavior honestly π«Ά
π« forEach π«
Runs a provided code reference (a reference to a subroutine or an anonymous subroutine) once per NodeList element, passing the element as an argument to the subroutine. It's the "do a thing for every node" method, and it ate π₯
Example:
my $node = $doc->createElement("div");
my $kid1 = $doc->createElement("p");
my $kid2 = $doc->createTextNode("hey");
my $kid3 = $doc->createElement("span");
$node->appendChild( $kid1 );
$node->appendChild( $kid2 );
$node->appendChild( $kid3 );
my $list = $node->childNodes;
$list->forEach(sub(currentValue, currentIndex, listObj)
{
my( $currentValue, $currentIndex, $listObj ) = @_;
say( "$currentValue, $currentIndex, $_" );
});
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach
π item π
Returns an item in the list by its index, or undef if the index is out-of-bounds. It's an alternative to accessing nodeList[i] (which instead returns undefined when i is out-of-bounds). This is mostly useful for non-JavaScript DOM implementations, iykyk β¨
Example:
my $tables = $doc->getElementsByTagName( 'table' );
my $firstTable = $tables->item(1); # or $tables->[1] - returns the second table in the DOM
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/item
π§ keys π§
Returns an iterator, allowing code to go through all the keys of the key/value pairs contained in the collection. (In this case, the keys are numbers starting from 0.) It's giving "index energy" π
Example:
my $node = $doc->createElement("div");
my $kid1 = $doc->createElement("p");
my $kid2 = $doc->createTextNode("hey");
my $kid3 = $doc->createElement("span");
$node->appendChild( $kid1 );
$node->appendChild( $kid2 );
$node->appendChild( $kid3 );
my $list = $node->childNodes;
# Using for..of
foreach my $key ( $list->keys->list )
{
say( $key );
}
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/keys
π values π
Returns an iterator allowing code to go through all values (nodes) of the key/value pairs contained in the collection. Yes bestie, the nodes themselves π
Example:
my $node = $doc->createElement("div");
my $kid1 = $doc->createElement("p");
my $kid2 = $doc->createTextNode("hey");
my $kid3 = $doc->createElement("span");
$node->appendChild( $kid1 );
$node->appendChild( $kid2 );
$node->appendChild( $kid3 );
my $list = $node->childNodes;
# Using for..of
foreach my $value ( $list->values )
{
say( $value );
}
See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/values
π«Ά AUTHOR π«Ά
Jacques Deguest β jack@deguest.jp
πΈ SEE ALSO πΈ
Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/NodeList
π COPYRIGHT & LICENSE π
Copyright(c) 2022 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.
okay that's the page, bestie: perl v5.42.2, dated 2026-02-15, and it's HTML::O...NodeList(3) β slay, bye π
πβ¨
π¦ 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