Entry
How can I insert a TABLE into an existing one?
Jun 24th, 2000 09:08
Martin Honnen,
IE4+ and NN6 support the
innerHTML
property of HTMLElements, so get a reference to an existing table cell
and set the innerHTML property:
var cell = document.all ? document.all['cellID'] :
document.getElementById ? document.getElementById('cellID') : null;
if (cell)
cell.innerHTML =
'<TABLE BGCOLOR="orange" BORDER="1">'
+ '<TR><TD STYLE="color: white;">JavaScript.FAQTs.com'
+ '<\/TD><\/TR><TABLE>';
Here is another example
<HTML>
<HEAD>
<STYLE>
</STYLE>
<SCRIPT>
var colors = ['red', 'green', 'blue', 'yellow'];
var c = 0;
function addTable (cell) {
var html = '<TABLE BORDER="1" BGCOLOR="' + colors[c] + '">';
html += '<TR><TD ONCLICK="addTable(this)">click me to add
table<\/TD><TD>Kibology<\/TD><\/TR><\/TABLE>';
cell.innerHTML = html;
c = ++c % colors.length;
cell.onclick = null;
}
</SCRIPT>
</HEAD>
<BODY>
<TABLE BORDER="1">
<TR>
<TD ONCLICK="addTable(this)">
click me to add a table
</TD>
</TR>
</TABLE>
</BODY>
</HTML>