Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Problem with table col in DOM. Please help!

    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';
    Last edited by mqasem; 07-23-2004 at 11:02 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I didn't know you could create a column using DOM... I didn't even know what it was! I thought a column was just a particular cell on every row..

    I'm still not sure that you can refer to a column the way you are, and that's why I think there's no CSS that would work on that column that way. I think you would have to go through each TR and find the particular TD that you needed (to isolate that 'column') and set the style/className individually.

    Either way, I've not seen anywhere that a column is created like this:
    document.createElement("COL");

    But rather this way:
    document.createElement("COLUMN");

    I don't know which way is correct, but that may be something..

    Hope that helps,
    Sadiq.

  • #3
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I haven't seen it myself, but I thought that any w3c tag would be DOM ready. This col tag can be included in a table the following way:

    <table>
    <col style="color:red">
    <col style="color:blue">
    <tr>
    <td>cell11</td>
    <td>cell12</td>
    </tr>
    <tr>
    <td>cell21</td>
    <td>cell22</td>
    </tr>
    </table>

    the red color will affect cell11, and 21, and the blue color will affect cell12, and 22.

  • #4
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK... I think I got closer to understanding DOM more. It turns out (I think) that DOM does not support col tag within the model, although it works if you create a col tag in a table using pure and unadulterated form of HTML. Let me explain how reached this conclustion (or semi-conclusion).

    In my code I included:

    <div id="myText">
    </div>
    <script>
    document.all['myText'].innerText = document.body.innerHTML;
    </script>

    What this did was display the HTML coding that was generated by the script. It turned out that the HTML code was formatted correctly. Why, then, didn't it work?

    To find out if the HTML code works I copied it into another file, and loaded it into the browser. It worked!! That means that I can't script col into being, but I can certainly HTML it.

    I guess I would have to work with cells if I wanted to control my columns through DOM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •