mqasem
07-23-2004, 09:51 PM
I created a table using DOM, and gave every cell an id. I also included col tags in the table, and gave them id's. Now, I can easily set the styles of the cells, but I can't seem to be able to change the style of the columns. The following is the code. I hope someone knows how to fix it.
Thank you
function Table(rows, columns, id)
{
var cellAttrib;
var colAttrib;
var myLocation = document.getElementById(id);
mytable = document.createElement("TABLE");
mytablebody = document.createElement("TBODY");
for (i = 0; i < columns; i++)
{
myColumn = document.createElement("COL");
myColumn.setAttribute("id","col_" + i);
mytablebody.appendChild(myColumn);
}
for(j = 0; j < rows; j++)
{
mycurrent_row = document.createElement("TR");
for(i = 0; i < columns; i++)
{
mycurrent_cell = document.createElement("TD");
currenttext = document.createTextNode("cell is row " + j + ", column " + i);
mycurrent_cell.appendChild(currenttext);
mycurrent_cell.setAttribute("id","cell_" + j + "_" + i);
mycurrent_row.appendChild(mycurrent_cell);
}
mytablebody.appendChild(mycurrent_row);
}
mytable.appendChild(mytablebody);
myLocation.appendChild(mytable);
mytable.setAttribute("border","2");
}
// Later in the HTML coding I include the following:
// This is how I call the above function to create a table.
// Don't worry about the GridID stuff.
// This is just where I place the table.
var myTable = new Table(10, 5, "GridID");
// This is where I attempt to change the color style of the col.
// No success here!
document.all['col_1'].style.color = 'red';
Thank you
function Table(rows, columns, id)
{
var cellAttrib;
var colAttrib;
var myLocation = document.getElementById(id);
mytable = document.createElement("TABLE");
mytablebody = document.createElement("TBODY");
for (i = 0; i < columns; i++)
{
myColumn = document.createElement("COL");
myColumn.setAttribute("id","col_" + i);
mytablebody.appendChild(myColumn);
}
for(j = 0; j < rows; j++)
{
mycurrent_row = document.createElement("TR");
for(i = 0; i < columns; i++)
{
mycurrent_cell = document.createElement("TD");
currenttext = document.createTextNode("cell is row " + j + ", column " + i);
mycurrent_cell.appendChild(currenttext);
mycurrent_cell.setAttribute("id","cell_" + j + "_" + i);
mycurrent_row.appendChild(mycurrent_cell);
}
mytablebody.appendChild(mycurrent_row);
}
mytable.appendChild(mytablebody);
myLocation.appendChild(mytable);
mytable.setAttribute("border","2");
}
// Later in the HTML coding I include the following:
// This is how I call the above function to create a table.
// Don't worry about the GridID stuff.
// This is just where I place the table.
var myTable = new Table(10, 5, "GridID");
// This is where I attempt to change the color style of the col.
// No success here!
document.all['col_1'].style.color = 'red';