Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/tabular-data/the-tr-element/deleteCell.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTMLTableRowElement#deleteCell</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<table>
<tr id="testTr">
<td>ABCDE</td>
<td>12345</td>
<td>ABC12</td>
</tr>
</table>
<script>
var tr = document.getElementById("testTr");
test(function () {
tr.deleteCell(0);
assert_equals(tr.cells[0].innerHTML, "12345");
assert_equals(tr.cells.length, 2);
}, "HTMLTableRowElement deleteCell(0)");
test(function () {
tr.deleteCell(-1);
assert_equals(tr.cells[tr.cells.length - 1].innerHTML, "12345");
assert_equals(tr.cells.length, 1);
}, "HTMLTableRowElement deleteCell(-1)");
test(function () {
assert_throws_dom("IndexSizeError", function () {
tr.deleteCell(-2);
});
}, "HTMLTableRowElement deleteCell(-2)");
test(function () {
assert_throws_dom("IndexSizeError", function () {
tr.deleteCell(tr.cells.length);
});
}, "HTMLTableRowElement deleteCell(cells.length)");
test(function () {
assert_equals(tr.cells.length, 1);
tr.deleteCell(-1);
assert_equals(tr.cells.length, 0);
tr.deleteCell(-1);
assert_equals(tr.cells.length, 0);
}, "HTMLTableRowElement deleteCell(-1) with no cells");
test(function () {
assert_equals(tr.cells.length, 0);
assert_throws_dom("IndexSizeError", function () {
tr.deleteCell(0);
});
}, "HTMLTableRowElement deleteCell(0) with no cells");
</script>