Index or size negative or greater than the allowable amount (non-negative indexes)

When using Firefox, I continue to get the error described in the subject line for this block of code:

for(var i = 0; i < tables.length; i++)
{
    var j = rows.length - 1;
    while(j--)
    {                   
        if(hideDP && tables[i].innerHTML.indexOf(">D<") != -1)
        {   
            if(!platTag && !soulSilverTag && pearlTag)
            {
                tables[i].deleteRow(j);//ERROR IS ON THIS LINE
            }
        }

    }//end while loop (rows)
}//end for loop (tables)

I suspect that this error is due to the fact that I am somewhat new to creating reverse loops, but I specifically made a reverse loop in this example, because it made it easier to delete rows from the table. Note also that j is something like 24, and I am 0, so they are non-negative. Can someone shed some light on this for me?

EDIT: Full code can be found here .

+3
source share
2 answers

Strictly working with already published code, here are the problems that I see:

  • . rows? .

  • while(j--); var j = rows.length - 1; . , , . , , .

    , 4 , j 3, - -- : 2, 1, 0. , var j = rows.length; , , .

  • 2 if() j! ( , .) , j.

  • . , Pastebin.



script, :

, , tables[i].deleteRow(j); .

, , continue .

if.:)



, :

, , script, .

:
var rows = tables[i].getElementsByTagName("tr");

, [i] , .

, ; : var rows = tables[i].rows;

~~~~
script , :

  • . , . , :
    tables = document.getElementsByTagName("table");

    :

    var tables = document.querySelectorAll ("div.KonaBody > table.roundy");
    

    ... 4 , , .

  • , , :

    if(tables[i].getAttribute("style").indexOf("border: 3px solid") != -1)
    
  • var majorSections.
+5

, j >= , .

0

All Articles