Closed Bug 157578 Opened 22 years ago Closed 22 years ago

insertRow() and deleteRow() not functioning

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

VERIFIED INVALID

People

(Reporter: eric, Assigned: jst)

References

Details

insertRow() and deleteRow() on TABLE and TBODY are not working.

According to the W3C DOM Level 1, both TABLE and TBODY should support the 
insertRow() and deleteRow() methods.  I am using the following code to add a 
new table row to an existing table:

<html>

    <head>
        <title>Test of Tables</title>
        <script language="JavaScript">

            var cellNum = 1;

            function insertRow()
            {
                var table1 = document.getElementById( "Table1" );
                var tr = table1.insertRow();
                var td = document.createElement( "TD" );
                td.innerHTML = "This is table cell " + cellNum++;
                tr.appendChild( td );
                updateRowCount();
            }

            function deleteRow( index )
            {
                var table1 = document.getElementById( "Table1" );
                table1.tBodies[ 0 ].deleteRow( index );
                updateRowCount();
            }

            function updateRowCount()
            {
                var table1 = document.getElementById( "Table1" );
                var rowCount = document.getElementById( "RowCount" );
                rowCount.innerHTML = table1.tBodies[ 0 ].rows.length;
            }

        </script>
    </head>

    <body>
        <span id="RowCount">1</span>

        <p>

        <table id="Table1" width="50%" border="1" cellpadding="4" 
cellspacing="0">
            <thead>
                <tr>
                    <td>This is a table header</td>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>This is table cell 0</td>
                </tr>
            </tbody>
        </table>

        <p>

        <input type="button" value="Insert New Row" onclick="insertRow();">

        <p>

        <input type="button" value="Delete 4th Row" onclick="deleteRow( 3 );">
    </body>

</html>
var tr = table1.insertRow();

there's a number missing!
Status: UNCONFIRMED → RESOLVED
Closed: 22 years ago
Resolution: --- → INVALID
using insertRow() with out arguments is incorreect. It should be used as
insertRow(index).
then it's valid - never heared that and also can't found it in the spec..
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
Kai,

what part of my comment suggested this is valid ;)
Status: UNCONFIRMED → RESOLVED
Closed: 22 years ago22 years ago
Resolution: --- → INVALID
good question, maybe I read another comment? ;)
verifying
Status: RESOLVED → VERIFIED
Sorry guys...  That's what I get by following the MSDN Library documentation 
(Microsoft's documentation).  I expected that when they say their insertRow() 
method is implemented according to the W3C spec, I wouldn't need to check the 
spec myself.  But this *is* Microsoft, and it seems they are not too good at 
following specifications in Internet Exploder.  :-)

I'll look at the W3C spec directly in the future.  Thanks for the quick 
response!
*** Bug 286184 has been marked as a duplicate of this bug. ***
*** Bug 310661 has been marked as a duplicate of this bug. ***
Component: DOM: HTML → DOM: Core & HTML
QA Contact: stummala → general
You need to log in before you can comment on or make changes to this bug.