HTML::O...t::Table(3)

πŸ“¦ version 0.6.0, in alpine 3.24

okay bestie, so this is the manual page for HTML::O...t::Table(3) β€” formally known as HTML::Object::DOM::Element::Table and she is the table queen of the HTML Object DOM πŸ’…βœ¨ buckle up, because this is part one of two and we are going in.

🌸 NAME 🌸

HTML::Object::DOM::Element::Table β€” the HTML Object DOM Table Class, no cap πŸ‘‘

πŸ¦‹ SYNOPSIS πŸ¦‹

use HTML::Object::DOM::Element::Table;
my $table = HTML::Object::DOM::Element::Table->new ||
    die( HTML::Object::DOM::Element::Table->error, "\n" );

like, that's literally it. she's ready πŸŽ€

⭐ VERSION ⭐

v0.3.0

πŸ’œ DESCRIPTION πŸ’œ

so this interface gives you all the special properties and methods for manipulating the layout and presentation of tables in an HTML document β€” and these come on top of the regular HTML::Object::DOM::Element object interface that she already inherits. main character energy fr fr πŸ‘‘

tables can have, in this exact order:

  1. an optional caption element,
  2. zero or more colgroup elements,
  3. an optional thead element,
  4. either one of the following:
    • zero or more tbody elements
    • one or more tr elements
  5. an optional tfoot element
heads up bestie: the above is for reference only and is not enforced by this interface 🫢

🌈 INHERITANCE 🌈

she comes from a long line of icons, iykyk:

+-----------------------+     +---------------------------+     +-------------------------+     +----------------------------+     +-----------------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Table |
+-----------------------+     +---------------------------+     +-------------------------+     +----------------------------+     +-----------------------------------+

✨ PROPERTIES ✨

she inherits properties from her parent HTML::Object::DOM::Element β€” family business πŸ’–

πŸŽ€ caption πŸŽ€

is a table caption element representing the first caption that is a child of the element, or undef if none is found.

when set, if the object does not represent a caption, a HTML::Object::HierarchyRequestError error is returned. if a correct object is given, it is inserted in the tree as the first child of this element and the first caption that is a child of this element is removed from the tree, if any, and returned.

example, because we love a demo:

my $table = $doc->getElementsByTagName( 'table' )->first;
my $old_caption = $table->caption( $new_caption );
# or
$table->caption = $new_caption;

see also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/caption

πŸ¦‹ rows πŸ¦‹

read-only, she just observes πŸ’…

returns a HTML Collection containing all the rows of the element, that is all tr that are a child of the element, or a child of one of its thead, tbody and tfoot children. the rows members of a thead appear first, in tree order, and those members of a tbody last, also in tree order.

ngl, for performance improvement the collection is cached until changes are made that would affect the results 🫢

example time:

<table id="myTable">
    <tr></tr>
    <tbody>
        <tr></tr>
    </tbody>
</table>
my $rows = $doc->getElementById( 'myTable' )->rows;
say $rows->length; # 2
<table id="myTable2">
    <tr>
        <td>
            <table>
                <tr></tr>
            </table>
        </td>
    </tr>
    <tbody>
        <tr></tr>
    </tbody>
</table>
my $rows = $doc->getElementById( 'myTable2' )->rows;
say $rows->length; # Still 2

see also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/rows

🌸 tBodies 🌸

read-only πŸŽ€

returns a HTML Collection containing all the tbody of the element.

again, for performance improvement the collection is cached until changes are made that would affect the results ✨

see also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/tBodies

πŸ“ tbodies πŸ“

alias for tBodies β€” same girl, different spelling, we love a nickname 😌

πŸ”₯ tFoot πŸ”₯

is a HTML::Object::DOM::Element::TableSection representing the first tfoot that is a child of the element, or undef if none is found.

when set, if the object does not represent a tfoot, a HTML::Object::HierarchyRequestError error is returned.

if a correct object is given, it is inserted in the tree immediately before the first element that is neither a caption, a colgroup, nor a thead, or as the last child if there is no such element, and the first tfoot that is a child of this element is removed from the tree, if any.

see also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/tFoot

πŸ‘‘ tHead πŸ‘‘

is a HTML::Object::DOM::Element::TableSection representing the first thead that is a child of the element, or undef if none is found.

when set, if the object does not represent a thead, a HTML::Object::HierarchyRequestError error is returned.

if a correct object is given, it is inserted in the tree immediately before the first element that is neither a caption, nor a colgroup, or as the last child if there is no such element, and the first thead that is a child of this element is removed from the tree, if any.

see also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/tHead


okay that's the properties section β€” but bestie, we are not done, there's more coming in part two, so don't go anywhere πŸ«ΆπŸ’–

πŸ’… METHODS πŸ’…

Ok so first things first: this class inherits methods from its parent HTML::Object::DOM::Element β€” free methods, no cap. πŸ’–

createCaption

Returns an HTML::Object::DOM::Element representing the first caption that is a child of the element. If none is found, a new one is created and inserted in the tree as the first child of the table element.

Example:

<table>
    <tr><td>Cell 1.1</td><td>Cell 1.2</td><td>Cell 1.3</td></tr>
    <tr><td>Cell 2.1</td><td>Cell 2.2</td><td>Cell 2.3</td></tr>
</table>

my $table = $doc->querySelector('table');
my $caption = $table->createCaption();
$caption->textContent = 'This caption was created by JavaScript!';

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/createCaption

createTBody

Returns an HTML::Object::DOM::Element::TableSection representing a new tbody that is a child of the element. It is inserted in the tree after the last element that is a tbody, or as the last child if there is no such element.

Example:

my $mybody = $mytable->createTBody();
# Now this should be true: $mybody == mytable->tBodies->item( $mytable->tBodies->length - 1 )

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/createTBody

createTFoot

Returns an HTML::Object::DOM::Element::TableSection representing the first tfoot that is a child of the element. If none is found, a new one is created and inserted in the tree as the last child.

Example:

my $myfoot = $mytable->createTFoot();
# Now this should be true: $myfoot == $mytable->tFoot

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/createTFoot

createTHead

Returns an HTML::Object::DOM::Element::TableSection representing the first thead that is a child of the element. If none is found, a new one is created and inserted in the tree immediately before the first element that is neither a caption, nor a colgroup, or as the last child if there is no such element.

Example:

my $myhead = mytable->createTHead();
# Now this should be true: $myhead == mytable->tHead

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/createTHead

deleteCaption

Removes the first caption that is a child of the element and returns the object of the caption element.

Example:

<table>
    <caption>This caption will be deleted!</caption>
    <tr><td>Cell 1.1</td><td>Cell 1.2</td></tr>
    <tr><td>Cell 2.1</td><td>Cell 2.2</td></tr>
</table>

my $table = $doc->querySelector('table');
$table->deleteCaption();

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/deleteCaption

deleteRow

Removes the row corresponding to the index given in parameter. If the index value is -1 the last row is removed; if it smaller than -1 or greater than the amount of rows in the collection, an HTML::Object::IndexSizeError is returned.

Example:

<table>
    <tr><td>Cell 1.1</td><td>Cell 1.2</td><td>Cell 1.3</td></tr>
    <tr><td>Cell 2.1</td><td>Cell 2.2</td><td>Cell 2.3</td></tr>
    <tr><td>Cell 3.1</td><td>Cell 3.2</td><td>Cell 3.3</td></tr>
</table>

my $table = $doc->querySelector('table');
# Delete second row
$table->deleteRow(1);

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/deleteRow

deleteTFoot

Removes the first tfoot that is a child of the element and returns the object of the caption element.

Example:

<table>
    <thead><th>Name</th><th>Score</th></thead>
    <tr><td>Bob</td><td>541</td></tr>
    <tr><td>Jim</td><td>225</td></tr>
    <tfoot><th>Average</th><td>383</td></tfoot>
</table>

my $table = $doc->querySelector('table');
$table->deleteTFoot();

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/deleteTFoot

deleteTHead

Removes the first thead that is a child of the element and returns the object of the caption element.

Example:

<table>
    <thead><th>Name</th><th>Occupation</th></thead>
    <tr><td>Bob</td><td>Plumber</td></tr>
    <tr><td>Jim</td><td>Roofer</td></tr>
</table>

my $table = $doc->querySelector('table');
$table->deleteTHead();

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/deleteTHead

insertRow

Returns an HTML::Object::DOM::Element::TableRow representing a new row of the table. It inserts it in the rows collection immediately before the tr element at the given index position, if any was provided. If there are no existing rows yet, a tbody is created and the new row inserted into it. If a table has multiple tbody elements, by default, the new row is inserted into the last tbody.

If the index is not given or is -1, the new row is appended to the collection. If the index is smaller than -1, it will start that far back from the end of the collection array. If index is greater than the number of rows in the collection, an HTML::Object::IndexSizeError error is returned.

Example:

<table></table>

$doc->getElementsByTagName('table')->[0]->insertRow();

Table is now:

<table>
    <tbody>
        <tr></tr>
    </tbody>
</table>

But if there are already existing rows and no tbody, the new row will merely be added as the last child of the table.

<table>
    <tr></tr>
</table>

$doc->getElementsByTagName('table')->[0]->insertRow();

Table is now:

<table>
    <tr></tr>
    <tr></tr>
</table>

Even if there is a tfoot, the new row will be added after:

<table>
    <tr></tr>
    <tfoot></tfoot>
</table>

$doc->getElementsByTagName('table')->[0]->insertRow();

Table is now:

<table>
    <tr></tr>
    <tfoot></tfoot>
    <tr></tr>
</table>

If an index is negative, the new row will be added that far back from the end:

<table>
    <tr id="one"></tr>
    <tr id="two"></tr>
    <tr id="three"></tr>
</table>

$doc->getElementsByTagName('table')->[0]->insertRow(-2);

Table is now:

<table>
    <tr id="one"></tr>
    <tr></tr>
    <tr id="two"></tr>
    <tr id="three"></tr>
</table>

See also Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/insertRow

🚫 DEPRECATED PROPERTIES 🚫

🚨 Heads up, bestie: these are deprecated/obsolete. They're here because the original lists them, not because you should reach for them in a new build. πŸ’€

πŸ‘‘ AUTHOR πŸ‘‘

Jacques Deguest <jack@deguest.jp>

πŸ¦‹ SEE ALSO πŸ¦‹

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.

πŸ’– That's the whole vibe. This page came from perl v5.42.2 and was dated 2026-02-15 β€” now go make your tables iconic, bestie. πŸŽ€

πŸ“¦ where this page comes from