A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/es/docs/Web/API/HTMLTableElement/insertRow below:

HTMLTableElement.insertRow() - API web | MDN

HTMLTableElement.insertRow()

Baseline Widely available

El método HTMLTableElement.insertRow() inserta una nueva fila en la tabla.

Sintaxis
var row = HTMLTableElement.insertRow(optional index = -1);
Ejemplo
<table id="TableA">
  <tr>
    <td>Antigua fila superior</td>
  </tr>
</table>
<script type="text/javascript">
  function addRow(tableID) {
    // Obtiene una referencia a la tabla
    var tableRef = document.getElementById(tableID);

    // Inserta una fila en la tabla, en el índice 0
    var newRow = tableRef.insertRow(0);

    // Inserta una celda en la fila, en el índice 0
    var newCell = newRow.insertCell(0);

    // Añade un nodo de texto a la celda
    var newText = document.createTextNode("Nueva fila superior");
    newCell.appendChild(newText);
  }

  // Llama a addRow() con el ID de la tabla
  addRow("TableA");
</script>

Para ser válida en un documento HTML, una TR debe contener al menos un elemento TD.

Observese que insertRow inserta la fila diréctamente en la tabla y retorna una referencia a la nueva fila. La fila no necesita ser añadida separadamente (p.e. con document.appendChild()) tal sería el caso si se usase document.createElement() para crear el nuevo elemento TR.

Especificaciones Compatibilidad con navegadores Ver también

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4