javascript iterate through table

Discussion in 'Web Design and Development' started by mbpowner, Dec 1, 2016.

  1. mbpowner macrumors regular

    Aug 19, 2016
    <!DOCTYPE html>

    var table=document.getElementById("myTable");
    for (var i = 0, i < table.rows.length; i++)
    var one=(table.rows.cells[1].innerHTML);



    <table border="1" id="myTable">







    this is just a test to see whether tables can be iterated through using this method, however no output is produced using the javascript code. can anyone suggest why? please thanks
  2. 960design, Dec 3, 2016
    Last edited: Dec 3, 2016

    960design macrumors 68030

    Apr 17, 2012
    Destin, FL
    Looks like you made a couple of mistakes:
    1. <script> in header is running before body exists... so a null return
    2. comma in for loop, instead of a semicolon
    3. missed adding the index to the row[]
    Check the JSBIN ( remember to put the <script> tags right at the bottom of code, right above the closing </body> tag,js,console

    PS. looks like I forgot to iterate the iterator... can you fix it?

Share This Page