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

HTMLTableElement: insertRow() - Web API | MDN

MDN Web Docs

View in English Always switch to English

HTMLTableElement: insertRow()

Baseline

20157

HTMLTableElement.insertRow() (<tr>) <table>

<tbody> <tbody> <tbody>

js
let specific_tbody = document.getElementById(tbody_id);
let row = specific_tbody.insertRow(index);

: insertRow() Document.createElement() <tr>

js
insertRow()
insertRow(index)

HTMLTableElement HTML <table>

index

index -1 index -1

HTMLTableRowElement

IndexSizeError DOMException

index

insertRow(-1)

HTMLTableRowElement.insertCell() HTML <tr> 1 <td> Document.createTextNode() Node.appendChild()

HTML

html
<table id="my-table">
  <tr>
    <td> 1</td>
  </tr>
  <tr>
    <td> 2</td>
  </tr>
  <tr>
    <td> 3</td>
  </tr>
</table>

JavaScript

js
function addRow(tableID) {
  // 
  let tableRef = document.getElementById(tableID);

  // 
  let newRow = tableRef.insertRow(-1);

  //  0 
  let newCell = newRow.insertCell(0);

  // 
  let newText = document.createTextNode("");
  newCell.appendChild(newText);
}

// addRow()  ID 
addRow("my-table");

HTML
# dom-table-insertrow-dev


Web Proxy Viewer  |  New URL  |  Original Page