Internet Explorer insertRow/insertCell failure

Discussion in 'Javascript' started by Howard Jess, Nov 4, 2005.

  1. Howard Jess

    Howard Jess Guest

    CLJ --

    I've searched the newsgroup and FAQ for info on insertRow(), but
    didn't see this reported.

    It seems that Internet Explorer doesn't respond correctly to either
    insertRow() or insertCell(), if the object that calls this method isn't
    already within a table. That is:

    row = tbody.insertRow(0); // fails if tbody's parent is null
    cell = row.insertCell(0); // fails if row's parent or grandparent is null

    By "fail", I mean the method returns null. As I understand the DOM spec,
    this behavior is wrong. Am I missing something? Mozilla, Opera, and
    Safari work as expected.

    Thanks for any help.

    Howard Jess

    Test file:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html><head><title>Table API test</title>
    <style type="text/css">
    table{border:1px dotted #999;margin:2px;background-color:#ddd}
    </style>
    <script type="text/javascript">
    function buildTable(divid) {
    var row,cell,tbody,table;

    tbody = document.createElement('tbody');
    row = tbody.insertRow(0);
    cell = row.insertCell(0);
    cell.appendChild(document.createTextNode('tablecell'));

    table = document.createElement('table');
    table.appendChild(tbody);
    document.getElementById(divid).appendChild(table);
    return false;
    }
    </script>
    </head><body>
    <h1>Table API Test</h1>
    <div id="tableDiv"></div>
    <form action="" onsubmit="return buildTable('tableDiv')">
    <p><input type="submit" value="Build Table"></p>
    </form></body></html>
     
    Howard Jess, Nov 4, 2005
    #1
    1. Advertising

  2. Howard Jess

    RobG Guest

    Howard Jess wrote:
    > CLJ --
    >
    > I've searched the newsgroup and FAQ for info on insertRow(), but
    > didn't see this reported.
    >
    > It seems that Internet Explorer doesn't respond correctly to either
    > insertRow() or insertCell(), if the object that calls this method isn't
    > already within a table. That is:
    >
    > row = tbody.insertRow(0); // fails if tbody's parent is null
    > cell = row.insertCell(0); // fails if row's parent or grandparent is null
    >
    > By "fail", I mean the method returns null. As I understand the DOM spec,
    > this behavior is wrong. Am I missing something? Mozilla, Opera, and
    > Safari work as expected.


    Perhaps not strictly 'wrong', but certainly 'not as expected'. The logic
    might be that a tbody must belong to a table, and a row to a tbody and a
    table. But that seems like making excuses: when building elements
    dynamically they must exist for some (short) time with invalid
    structures - rows will not have cells when they are created, nor tbodys
    rows, etc.


    The Microsoft documentation says:

    "If you insert a row in a tFoot, tBody, or tHead, you also need to
    add the row to the rows collection for the table. If you insert a
    row in the table, you also need to add the row to the rows collection
    for the tBody."

    <URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/insertrow.asp>


    Confusing (their code example is not worth quoting)?

    Just another IE quirk?


    [...]

    --
    Rob
     
    RobG, Nov 5, 2005
    #2
    1. Advertising

  3. Gérard Talbot, Nov 5, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roedy Green

    Internet Explorer Java Failure

    Roedy Green, Apr 19, 2004, in forum: Java
    Replies:
    15
    Views:
    4,091
    Steven J Sobol
    May 1, 2004
  2. Replies:
    0
    Views:
    1,129
  3. will

    insertCell problems

    will, Aug 14, 2003, in forum: Javascript
    Replies:
    4
    Views:
    150
  4. putty
    Replies:
    1
    Views:
    273
    putty
    Apr 5, 2005
  5. Replies:
    1
    Views:
    116
Loading...

Share This Page