Using the cloneNode Method
/*
JavaScript Unleashed, Third Edition
by Richard Wagner and R. Allen Wyke
ISBN: 067231763X
Publisher Sams CopyRight 2000
*/
<HTML>
<HEAD>
<TITLE> DOM cloneNode example </TITLE>
</HEAD>
<BODY ID="bodyNode">
<TABLE ID="tableNode">
<TBODY>
<TR ID="tr1Node">
<TD BGCOLOR="yellow">Row 1, Cell 1</TD>
<TD BGCOLOR="orange">Row 1, Cell 2</TD>
</tr>
<TR ID="tr2Node">
<TD BGCOLOR="red">Row 2, Cell 1</TD>
<TD BGCOLOR="magenta">Row 2, Cell 2</TD>
</tr>
<TR ID="tr3Node">
<TD BGCOLOR="lightgreen">Row 3, Cell 1</TD>
<td BGCOLOR="beige">Row 3, Cell 2</TD></TR>
<TR ID="tr4Node">
<TD BGCOLOR="blue">Row 4, Cell 1</TD>
<TD BGCOLOR="lightblue">Row 4, Cell 2</TD>
</tr>
<TR ID="tr5Node">
<TD BGCOLOR="orange">Row 5, Cell 1</TD>
<TD BGCOLOR="purple">Row 5, Cell 2</TD>
</tr>
</TBODY>
</TABLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
tr3Obj = tr1Node.cloneNode(false);
alert(
"tr3Obj.firstChild = " + tr3Obj.firstChild + "\n" +
"tr3Obj.nodeName = " + tr3Obj.nodeName
);
// -->
</SCRIPT>
</BODY>
</HTML>
Related examples in the same category