Women in Technology

Hear us Roar

  Dynamic Content with DOM-2 (Part I of II)
Subject:   Inserting Nodes without pre-existing table
Date:   2002-04-29 18:32:44
From:   madmiarde
Your article was great! In stepping through some of your examples, specifically the "Inserting Nodes in a Sequence" portion, I can't figure out how you would do it if the table didn't exist already. Your example started with a table, row and three data cells. I can duplicate this without problem. When I try to start with an empty table, it will not work. Here's what I start with:

<table id="table1">

I then try to create a new row and add a cell to it with this:

//get reference to the table on the form
var t1 = document.getElementById( "table1" );

//create a row
var tr1 = document.createElement( "tr" );
tr1.setAttribute( "id", "tr1" );
t1.appendChild( tr1 );
//create cell
var td1 = document.createElement( "td" );
var td1Text = document.createTextNode( "cell text" );
td1.appendChild( td1Text );
tr1.appendChild( td1 );

I even tried getting another reference to the row and using it instead of the existing reference(tr1):
var tr1Ref = document.getElementById("tr1");

But I had no luck. I even tried splitting the row and cell into different fucntions but still nothing (just humoring myself). Any ideas? Is it possible?

Thanks again for the great article! Running IE5.5 on WinME.

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • Inserting Nodes without pre-existing table
    2002-06-13 07:13:38  iq_soft [View]

    The point is also to create TBODY element
    within your table. Try this:
    <tbody id="table1">

    and the rest of your code should work....
    at least it works for me (IE, NS, Mozilla)
    • Inserting Nodes without pre-existing table
      2002-06-14 12:53:19  madmiarde [View]

      Thanks for the reply! You were correct - the only thing I was missing was the tbody element. I found it in an article on Microsoft's site.

      Thanks again!