I have written a javascript code to dynamically generate a table ,How can I add class attribute to genrated table?
I have tried using addClass(), and .className. But it did't work for me.
Here is my code :
var res = data.split("\n");
rows = res.length;
var body = document.getElementById(name);
tbl = document.createElement('table');
tbl.style.width = '100px';
tbl.style.border = "1px solid black";
//tb1.class("table"); tb1.className="table" tn.addClass() ="table"
for(var i = 1; i < rows; i++)
{
var tr = tbl.insertRow();
var column = res[i].split("@");
cols = column.length;
for(var j = 0; j < cols; j++)
{
var td = tr.insertCell();
td.appendChild(document.createTextNode(column[j]));
td.style.border = "1px solid black";
}
}
body.appendChild(tbl);
}
I have written a jquery codeThere is no jQuery there