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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CSS formatting DOM table cells. Help.

    The following code add rows and cells nicely in a table.
    I need to apply some css formatting like fontfamily, fontsize, padding, etc., to the cells. Please advise.

    <html>
    <head>
    <script language="JavaScript" type="text/javascript">
    function addRow(id){
    var tbody = document.getElementById
    (id).getElementsByTagName("TBODY")[0];
    var row = document.createElement("TR")
    var td1 = document.createElement("TD")
    td1.appendChild(document.createTextNode("efgh"))
    var td2 = document.createElement("TD")
    td2.appendChild (document.createTextNode("5678"))
    row.appendChild(td1);
    row.appendChild(td2);
    tbody.appendChild(row);
    }

    </script>
    </head>
    <body>
    <br><br><br>
    <a href="#" onclick="addRow('myTable');return false;">Add row</a>
    <table id="myTable" cellspacing="0" border="1">
    <tbody>
    <tr>
    <td>abcd</td><td>1234</td>
    </tr>
    </tbody>
    </table>

    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Would you like to elaborate on that a little?

    Like what CSS? Have you got some style classes together already or are you asking for our advice as to 'what looks good'?

    Or are you asking where/how you would change CSS attributes? This is one we can help you out with:
    Code:
    row.className = 'cssClassName';
    row.setAttribute('className', 'cssClassName');
    row.style.bgColor = 'blue';
    Hope that helps,
    Sadiq.


  •  

    Posting Permissions

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