Upload
vijayakumarmani
View
24
Download
5
Embed Size (px)
DESCRIPTION
The document is download via internet
Citation preview
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, noregistration required.
Create table using Javascript
I have a JavaScript function which creates a table with 3 rows 2 cells.Could anybody tell me how I can create the table below using my function (i need to do this for mysituation)?My HTML:
JavaScript:
function tableCreate() {
//body reference
var body = document.getElementsByTagName("body")[0];
// create elements and a
var tbl = document.createElement("table");
var tblBody = document.createElement("tbody");
// cells creation
for (var j = 0; j
javascript html table
asked Feb 1 '13 at 9:54Manny Fitzgerald102 1 1 5
4 Answers
This should work (from a few alterations to your code above).
function tableCreate(){
var body=document.getElementsByTagName('body')[0];
var tbl=document.createElement('table');
tbl.style.width='100%';
tbl.setAttribute('border','1');
var tbdy=document.createElement('tbody');
for(var i=0;i
}
body.appendChild(tbl);
}
tableCreate();
Also, this doesn't use some "bad practices", such as setting a attribute instead ofusing CSS, and it accesses the through instead of
;
border
body document.body
document.getElementsByTagName('body')[0]
edited Dec 4 '14 at 10:10 answered Feb 1 '13 at 10:38Cerbrus22.7k 4 26 55
Insert title here
var student;
for(var j=0;j
create table
function create() {
var row = parseInt(document.getElementById("row").value);
var col = parseInt(document.getElementById("col").value);
var tablestart="";
var tableend = "";
var trstart = "";
var trend = "";
var tdstart = "";
var tdend = "";
var data="data in cell";
var str1=tablestart + trstart + tdstart + data + tdend + trend + tableend;
document.write(tablestart);
for (var r=0;r