Creating a Table : DOM Content : Development JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Development » DOM Content »

 

Creating a Table




<HTML>
<HEAD>
<TITLE> Building tables using DOM </TITLE>
</HEAD>
<BODY ID="bodyNode">
<SCRIPT LANGUAGE="JavaScript">
<!--
row1column1Node = document.createTextNode("test");
tableElement = document.createElement("TABLE");
tableBodyElement = document.createElement("TBODY");
tr1Element = document.createElement("TR");
tr1td1 = document.createElement("TD");

tr1td2 = tr1td1.cloneNode(true);
tr2td1 = tr1td1.cloneNode(false);
tr2td2 = tr1td1.cloneNode(true);
tr3td1 = tr1td1.cloneNode(false);
tr3td2 = tr1td1.cloneNode(false);

tr2 = tr1Element.cloneNode(true);
tr3 = tr1Element.cloneNode(false);

row1column2 = row1column1Node.cloneNode(false);
row2column1 = row1column1Node.cloneNode(true);

row2column2 = row1column1Node.cloneNode(false);
row3column1 = row1column1Node.cloneNode(true);
row3column2 = row1column1Node.cloneNode(false);

row1column2.nodeValue = "A  ";
row2column1.nodeValue = "B  ";
row2column2.nodeValue = "C  ";
row3column1.nodeValue = "D  ";
row3column2.nodeValue = "E  ";

returnValue = tableElement.insertBefore(tableBodyElement);

tableBodyElement.insertBefore(tr3);
tableBodyElement.insertBefore(tr2, tr3);
tableBodyElement.insertBefore(tr1Element, tr2);

tr1Element.insertBefore(tr1td2);
tr1Element.insertBefore(tr1td1, tr1td2);

tr2.insertBefore(tr2td2);
tr2.insertBefore(tr2td1, tr2td2);
tr3.insertBefore(tr3td2);
tr3.insertBefore(tr3td1, tr3td2);

tr1td2.insertBefore(row1column2);
tr1td1.insertBefore(row1column1Node);
tr2td2.insertBefore(row2column2);
tr2td1.insertBefore(row2column1);
tr3td2.insertBefore(row3column2);
tr3td1.insertBefore(row3column1);

bodyNode.insertBefore(tableElement);
// -->
</SCRIPT>
</BODY>
</HTML>
           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Development
» DOM Content