W3Schools.com

tr deleteCell() Method

tr Object Reference tr Object

Definition and Usage

The deleteCell() method deletes a cell in the current table row.

Syntax

trObject.deleteCell(index)

Value Description
index An integer (starts at 0) that specifies the position of the cell to delete in the current row. 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.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The deleteCell() method is supported in all major browsers.


Example

Example

Delete first cell from the first table row:

<html>
<head>
<script type="text/javascript">
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()">Delete first cell</button>

</body>
</html>

Try it yourself »


tr Object Reference tr Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE