.innerHTML and .innerText undefined

52 Views Asked by At

writing a tampermonkey script, grabbed an htmlcollection of all td's on the page with getElementsByTagName, returning 400+ tds. go to step through those to examine the contents of each td.. and debug console in browser is showing TypeError: Cannot read properties of undefined (reading 'innerText') or 'innerHTML' when I swap those two out. obv, I am referencing the items in the collection incorrectly, but I thought I was following examples...

var cells = document.getElementsByTagName("td");
var cellvalue = "example";
        /* steps through all the items in the array looking at each one individually */
        for (let i = 0; 1 < cells.length; i++) {
            /* grabs the contents of the td */
            cellvalue = cells[i].innerText;

I tried using .innerText, .innerHTML, and a few other things but I always get the same TypeError. console logging cells.length is showing correctly finding hundreds of tds, but I cant seem to reference them properly.

0

There are 0 best solutions below