docs.rodeo

MDN Web Docs mirror

HTMLTableElement

{{APIRef("HTML DOM")}} 

The HTMLTableElement interface provides special properties and methods (beyond the regular {{DOMxRef("HTMLElement")}}  object interface it also has available to it by inheritance) for manipulating the layout and presentation of tables in an HTML document.

{{InheritanceDiagram}} 

Instance properties

Inherits properties from its parent, {{DOMxRef("HTMLElement")}} .

Obsolete Properties

[!WARNING] The following properties are obsolete. You should avoid using them.

Instance methods

Inherits methods from its parent, {{DOMxRef("HTMLElement")}} .

Examples

Using the DOM Table Interface

The HTMLTableElement interface provides some convenience methods for creating and manipulating tables. Two frequently used methods are {{domxref("HTMLTableElement.insertRow")}}  and {{domxref("HTMLTableRowElement.insertCell")}} .

To add a row and some cells to an existing table:

<table id="table0">
  <tr>
    <td>Row 0 Cell 0</td>
    <td>Row 0 Cell 1</td>
  </tr>
</table>
const table = document.getElementById("table0");
const row = table.insertRow(-1);

for (let i = 0; i < 2; i++) {
  const cell = row.insertCell(-1);
  const text = `Row ${row.rowIndex} Cell ${i}`;
  cell.appendChild(document.createTextNode(text));
}

{{EmbedLiveSample("using_the_dom_table_interface", "", "300")}} 

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN