tr deleteCell()Método
Objeto trDefinición y uso
El método deleteCell() se utiliza para eliminar una celda (elemento <td>) de una fila de tabla.
Sintaxis
trObject.deleteCell(index)
| Valor | Descripción |
|---|---|
| index | El parámetro index es la posición de la celda que se va a eliminar en la fila. Este método eliminará la celda en la posición especificada en la fila de la tabla. |
Soporte del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales son compatibles con el método deleteCell().
Ejemplos
Ejemplos
El siguiente ejemplo elimina una celda de la fila:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<script>
function displayResult(){
var firstRow=document.getElementById("myTable").rows[0];
firstRow.deleteCell(0);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>First cell</td>
<td>Second cell</td>
<td>Third cell</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Eliminar la primera celda</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<script>
function displayResult(){
var firstRow=document.getElementById("myTable").rows[0];
firstRow.deleteCell(0);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>First cell</td>
<td>Second cell</td>
<td>Third cell</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Eliminar la primera celda</button>
</body>
</html>
¡Pruébalo! »
Objeto trOtras extensiones