HTML::O...NodeList(3)

πŸ“¦ version 0.6.0, in alpine 3.24

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(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