Javascript DOM <table> Iterate table rows

Description

Javascript DOM <table> Iterate table rows

View in separate window

<!DOCTYPE html>
<head>
<title>Recipe</title>
<script>
  window.onload = function() {//  ww w  .j a v  a  2  s  . c o  m

    let rows = document.getElementById("table1").children[0].rows;
    let numArray = new Array();

    for (let i = 0; i < rows.length; i++) {
      numArray[numArray.length] = parseInt(rows[i].cells[1].firstChild.data);
    }

    document.getElementById("demo").innerHTML = numArray.toString();
  }
</script>
</head>
<body>
    <p id="demo"></p>
  <table id="table1">
    <tr>
      <td>4.5</td>
      <td>5.3</td>
      <td>2</td>
    </tr>
  </table>
</body>
</html>



PreviousNext

Related