Jump to content

a question on tables


Guest three moons

Recommended Posts

tested and works in IE6 and FF2

<html><head></head><body><script>	var table = document.createElement("table");	table.border = "1";	table.cellPadding = "5";	var tbody = document.createElement("tbody");		var heading1 = document.createElement("th");	heading1.appendChild(document.createTextNode("Number"));		var heading2 = document.createElement("th");	heading2.appendChild(document.createTextNode("Square Root"));		var heading3 = document.createElement("th");	heading3.appendChild(document.createTextNode("Cube"));		var row = document.createElement("tr");		document.body.appendChild(table);	table.appendChild(tbody);	tbody.appendChild(row);	row.appendChild(heading1);	row.appendChild(heading2);	row.appendChild(heading3);		var num = 1;	while(num < 10)	{		row = null;		row = document.createElement("tr");				var cell1 = document.createElement("td");		cell1.appendChild(document.createTextNode(num));				var cell2 = document.createElement("td");		cell2.appendChild(document.createTextNode("Square root of " + num));				var cell3 = document.createElement("td");		cell3.appendChild(document.createTextNode("Cube of " + num));				tbody.appendChild(row);		row.appendChild(cell1);		row.appendChild(cell2);		row.appendChild(cell3);				num++;	}		//alert(document.body.innerHTML);</script></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...