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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Possible to create TH element using insertCell?

    It appears that using the insertCell method to append a cell to a table row in the tbody creates a data cell by default. I need to create a header cell (in the tbody, not in the thead). Is this possible?

    The desired result would be something like this:

    Code:
    <table>
        <tbody>
            <tr>
                <th>#text</th>  <-- I am unable to create this element.
                <td>#text</td>
                <td>#text</td>
            </tr>
        </tbody>
    </table>

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    It doesn't look like it. You'll have to createElement.

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    meta http-equiv="Content-Style-Type" content="text/css">
    <
    meta http-equiv="Content-Script-Type" content="text/javascript">
    <
    script language="JavaScript" type="text/JavaScript">
    function 
    createTh(){
    var 
    rootdocument.getElementById('tab').getElementsByTagName('tr')[0];
    var 
    eTh document.createElement('th');
    var 
    eTxt document.createTextNode('#text');
    var 
    ref root.getElementsByTagName('td')[0];
    eTh.appendChild(eTxt);
    root.insertBefore(eTh,ref);
    }
    onload=createTh;
    </script>
    </head>
    <body>
    <table id="tab">
     <tbody>
      <tr>
       <td>#text</td>
       <td>#text</td>
      </tr>
     </tbody>
    </table>
    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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