[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/API/HTMLTableElement/insertRow [Back]  [Original]

HTMLTableElement.insertRow() - API | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

HTMLTableElement.insertRow()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

HTMLTableElement.insertRow() .

In this article

var row = HTMLTableElement.insertRow(optional index = -1);
  • HTMLTableElement HTML table .
  • index
  • row . HTMLTableRowElement. index -1 , . index , IndexSizeError. index , -1.
  • tbody, , , tbody. tbody: var specific_tbody=document.getElementById(tbody_id); var row=specific_tbody.insertRow(index)

html
<table id="TableA">
  <tr>
    <td>Old top row</td>
  </tr>
</table>
<script type="text/javascript">
  function addRow(tableID) {
    // Get a reference to the table
    var tableRef = document.getElementById(tableID);

    // Insert a row in the table at row index 0
    var newRow = tableRef.insertRow(0);

    // Insert a cell in the row at index 0
    var newCell = newRow.insertCell(0);

    // Append a text node to the cell
    var newText = document.createTextNode("New top row");
    newCell.appendChild(newText);
  }

  // Call addRow() with the ID of a table
  addRow("TableA");
</script>

HTML , TR TD .

, insertRow . , document.createElement(), TR .

Specification
HTML
# dom-table-insertrow-dev


Web Proxy Viewer  |  New URL  |  Original Page