Metoda TableRow deleteCell().
Příklad
Odstraňte první buňku (buňky) z řádku tabulky s id="myRow":
var row = document.getElementById("myRow");
row.deleteCell(0);
Definice a použití
Metoda deleteCell() odstraní buňku v aktuálním řádku tabulky.
Tip: Pomocí metody insertCell() vložte buňku do aktuálního řádku tabulky.
Podpora prohlížeče
Method | |||||
---|---|---|---|---|---|
deleteCell() | Yes | Yes | Yes | Yes | Yes |
Syntax
tablerowObject.deleteCell(index)
Hodnoty parametrů
Value | Description |
---|---|
index | Required in Firefox and Opera, optional in IE, Chrome and Safari. An integer (starts at 0) that specifies the position of the cell to delete in the current row. The value of 0 results in that the first cell will be deleted. The value of -1 can also be used; which result in that the last cell will be deleted. If this parameter is omitted, deleteCell() removes the last cell in IE and the first cell in Chrome and Safari. This parameter is required in Firefox and Opera, but optional in Internet Explorer, Chrome and Safari. |
Technické údaje
Návratová hodnota: | Žádná návratová hodnota. |
---|
Další příklady
Příklad
Odstraňte poslední buňku(y) z řádku tabulky s id="myRow":
var row = document.getElementById("myRow");
row.deleteCell(-1);
Příklad
Odstraňte buňku(y) z pozice indexu 1 v řádku tabulky s id="myRow":
var row = document.getElementById("myRow");
row.deleteCell(1);
Příklad
Odstraňte buňky na začátku prvního řádku tabulky. Kolekce řádků tabulky (.rows[0]) vrací kolekci všech prvků <tr> v tabulce s id "myTable". Číslo [0] určuje prvek, který se má načíst, v tomto příkladu první řádek tabulky. Poté použijeme deleteCell() k odstranění buněk z pozice indexu 0:
var firstRow = document.getElementById("myTable").rows[0];
firstRow.deleteCell(0);
Příklad
Vložte nové buňky s obsahem na začátek řádku tabulky s id="myRow":
var row = document.getElementById("myRow");
var x = row.insertCell(0);
x.innerHTML = "New cell";
❮ Objekt TableRow