rows property

The rows property stores a collection of tr rows. It can be applied to both the table and its tHead, tBodies, tFoot sections.

Syntax

javascripttable.rows;

Example

Let's loop through all the rows of a table:

html<table id="table">
  <tr>
    <td>1</td><td>2</td><td>3</td>
  </tr>
  <tr>
    <td>4</td><td>5</td><td>6</td>
  </tr>
  <tr>
    <td>7</td><td>8</td><td>9</td>
  </tr>
</table>
javascriptlet table = document.querySelector('#table');

for (let row of table.rows) {
  console.log(row);
}

Example

Let's loop through all the rows of a table using the rows property, and in each row we loop through its cells using the cells property:

html<table id="table">
  <tr>
    <td>1</td><td>2</td><td>3</td>
  </tr>
  <tr>
    <td>4</td><td>5</td><td>6</td>
  </tr>
  <tr>
    <td>7</td><td>8</td><td>9</td>
  </tr>
</table>
javascriptlet table = document.querySelector('#table');

for (let row of table.rows) {
  for (let cell of row.cells) {
    console.log(cell);
  }
}

Example

We find the number of rows in a table:

html<table id="table">
  <tr>
    <td>1</td><td>2</td><td>3</td>
  </tr>
  <tr>
    <td>4</td><td>5</td><td>6</td>
  </tr>
  <tr>
    <td>7</td><td>8</td><td>9</td>
  </tr>
</table>
javascriptlet table = document.querySelector('#table');
console.log(table.rows.length);

The code execution result:

javascript3

See also

  • the cells property
    that contains table cells
  • the tHead property
    that contains thead of a table
  • the tFoot property
    that contains tfoot of a table
  • the tBodies property
    that contains tbody of a table