You are here: Reference > JavaScript > client-side > HTML DOM > methods > deleteRow (table, tbody, tfoot, thead)

deleteRow method (table, tbody, tfoot, thead)

Browser support:
Removes a row from the current table, thead, tfoot or tbody element.
To create and insert a row, use the insertRow method.

Syntax:

object.deleteRow (index);
You can find the related objects in the Supported by objects section below.

Parameters:

index
Required in Firefox and Opera, optional in Internet Explorer, Google Chrome and Safari. Zero-based integer that specifies the position of the row to delete in the rows collection of the current element. The value of -1 can also be used; in that case, the last row will be deleted. If this parameter is not specified, the deleteRow method removes the last row in Internet Explorer and the first row in Google Chrome and Safari.

Return value:

This method has no return value.

Example HTML code 1:

This example illusrates the use of the deleteRow method:
<head>
    <script type="text/javascript">
        function RemoveRow () {
            var table = document.getElementById ("myTable");
            if (table.rows.length > 0) {
                table.deleteRow (0);
            }
        }
    </script>
</head>
<body>
    <button onclick="RemoveRow ();">Remove the first row!</button>
    <table id="myTable" border="1px">
        <tbody>
            <tr>
                <td>First row.</td>
            </tr>
            <tr>
                <td>Second row.</td>
            </tr>
        </tbody>
    </table>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content