I encountered the problem that my script does not see the data from the collection

Viewed 31

To begin with, I extracted an element from the Html page:

const table = document.getElementsByClassName("b-table m-responsive m-earnings")

After which I tried to extract and output certain data from there to the console:

console.log(table['0']['childNodes'])

At the output in the console I get:

undefined

When entering these lines directly into the console on the website, I get this: enter image description here

Maybe someone knows what this can be connected with and how to fix it?

Html structure:

<table class="b-table m-responsive m-earnings">
<thead>
    <tr>
        <th>Date &amp; Time</th>
        <th>Amount</th>
        <th>Fee</th>
        <th>Net</th>
        <th>Description</th>
        <th>Status</th>
    </tr></thead>
<tbody>
    <!---->
    <tr>
        <td class="b-table__date">
            <span class="b-table__date__date">
                <span title=""> Sep 23, 2022 </span>
            </span>
            <span class="b-table__date__time">
                <span title=""> 12:03 pm </span>
            </span>
        </td>
        <td data-title="Amount" class="b-table__amount">
            <span class=""> $10.00 </span>
        </td>
        <td data-title="Fee" class="b-table__fee">
            <span class=""> $2.00 </span>
        </td>
        <td data-title="Net" class="b-table__net">
            <strong>
                <span class=""> $8.00 </span>
            </strong>
        </td>
        <td class="b-table__desc">
            <span>Payment for message from 
                <a href="/u227149512">LordHeiko</a>
            </span>
        </td>
        </tr>
        <tr>
            more and more tr
        </tr>
    </tbody>
1 Answers

based on what i understood, you want to access the thead elements and the tbody elements as well:

x = document.getElementsByClassName('b-table m-responsive m-earnings')[0].getElementsByTagName('thead')[0].getElementsByTagName('tr')[0].childNodes
// a shorter version
x = document.querySelectorAll('.b-table.m-responsive.m-earnings thead tr')[0].childNodes

this returns all the ths in the thead

x = document.getElementsByClassName('b-table m-responsive m-earnings')[0].getElementsByTagName('thead')[0].getElementsByTagName('tr')[0].childNodes
// shorter version
x = document.querySelectorAll('.b-table.m-responsive.m-earnings tbody tr')[0].childNodes

and this is for the tbody

if this is not what you want, you can clarify more in the comments.

Related