document.createElement in IE with TR tag

Discussion in 'Javascript' started by rain_c1@web.de, Oct 18, 2005.

  1. Guest

    Hi!

    I have problems with document.createElement() in IE when using TR tags.
    Please look at the following very short example:

    ------------snip-----------------
    <table id="test"></table>

    <script type="text/javascript">
    var MyTable = document.getElementById("test");
    var myTR = document.createElement('tr');
    var myTD = document.createElement('td');
    var myText = document.createTextNode("this is text");

    myTD.appendChild(myText);
    myTR.appendChild(myTD);
    MyTable.appendChild(myTR);
    </script>
    ------------snip-----------------

    this works fine in Firefox, but IE is very strange. It refuses to
    display the created elements. Through further tests I realized, that
    only the TR tag is the problem. If this is already in the static HTML
    code it works in IE, too.

    Further very strange: If I use the developer toolbar for IE and use the
    DOM Explorer, it shows me, that all my dynamic generated tags are
    there, but they are not displayed.

    Has anybody an idea?

    Thank you very much!

    Best regards,
    - Rainer
     
    , Oct 18, 2005
    #1
    1. Advertising

  2. Matt Kruse Guest

    wrote:
    > var MyTable = document.getElementById("test");


    Get a reference to the tbody element instead of the table element.
    When you don't explicitly put one in, IE puts one in for you.
    A TR can only be appended to a tbody.

    --
    Matt Kruse
    http://www.JavascriptToolbox.com
    http://www.AjaxToolbox.com
     
    Matt Kruse, Oct 18, 2005
    #2
    1. Advertising

  3. Guest

    this works very fine, thanks a lot!
     
    , Oct 18, 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. shruds
    Replies:
    1
    Views:
    845
    John C. Bollinger
    Jan 27, 2006
  2. Weston C

    document.createElement('a') doesn't work?

    Weston C, Jan 9, 2004, in forum: Javascript
    Replies:
    4
    Views:
    112
    Michael Hill
    Jan 9, 2004
  3. Pieter Van Waeyenberge

    'wrap' inconsistency? createElement VS document.write

    Pieter Van Waeyenberge, Feb 9, 2004, in forum: Javascript
    Replies:
    3
    Views:
    180
    Pieter Van Waeyenberge
    Feb 11, 2004
  4. oeyvind toft

    document.createElement

    oeyvind toft, Sep 4, 2004, in forum: Javascript
    Replies:
    4
    Views:
    147
    Michael Winter
    Sep 5, 2004
  5. James Black
    Replies:
    10
    Views:
    283
    Thomas 'PointedEars' Lahn
    May 25, 2006
Loading...

Share This Page