SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Oct 2007
    Location
    United Kingdom
    Posts
    622
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question Correct thead and tbody for a table structure?

    Hello, until recently I have always written a html table like this:

    Table Example 1a
    HTML Code:
    <table summary="an example of writing a table">
       <tr>
          <th scope="col">Table Header 1</th>
          <th scope="col">Table Header 2</th>
          <th scope="col">Table Header 3</th>
       </tr>
       <tr>
          <td>Table Data 1</td>
          <td>Table Data 1</td>
          <td>Table Data 1</td>
       </tr>
    <table>
    Table Example 2a
    HTML Code:
    <table summary="an example of writing a table">
       <tr>
    
          <th scope="row">Table Header 1</th>
          <td>Table Data 1</td>
    
          <th scope="row">Table Header 2</th>
          <td>Table Data 1</td>
    
          <th scope="row">Table Header 3</th>
          <td>Table Data 1</td>
    
       </tr>
    <table>
    But I while creating a JavaScript program, I have descovered that if I want to dynamically add a table in IE then the table needs a tbody or IE JavaScript refuses to add the table dynamically, so I am now trying to think how to use thead and tbody correctly.

    For example 1a it seems pretty easy:

    Table Example 1b
    HTML Code:
    <table summary="an example of writing a table">
       <thead>
          <tr>
             <th scope="col">Table Header 1</th>
             <th scope="col">Table Header 2</th>
             <th scope="col">Table Header 3</th>
          </tr>
       </thead>
       <tbody>
          <tr>
             <td>Table Data 1</td>
             <td>Table Data 1</td>
             <td>Table Data 1</td>
          </tr>
       </tbody>
    <table>
    But I dont know how you would do Table Example 2a ?

    Table Example 2b
    HTML Code:
    <!-- ????   :-S   ???? -->
    Thanks
    ro0bear
    Last edited by ro0bear; Apr 19, 2009 at 06:21. Reason: corrected spelling

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code HTML4Strict:
    <table summary="an example of writing a table">
      <tbody>
         <tr>
     
            <th scope="row">Table Header 1</th>
            <td>Table Data 1</td>
     
            <th scope="row">Table Header 2</th>
            <td>Table Data 1</td>
     
            <th scope="row">Table Header 3</th>
            <td>Table Data 1</td>
     
         </tr>
      </tbody>
    <table>
    In this case you don't have a table header, so there'll be no <thead> tag.

    (I must say example 2b looks odd. Should'nt it be like this?)
    Code HTML4Strict:
    <table summary="an example of writing a table">
      <tbody>
         <tr>
            <th scope="row">Table Header 1</th>
            <td>Table Data 1</td>
         </tr>
     
         <tr>
            <th scope="row">Table Header 2</th>
            <td>Table Data 2</td>
         </tr>
     
         <tr>
            <th scope="row">Table Header 3</th>
            <td>Table Data 3</td>
         </tr>
      </tbody>
    <table>
    (And you spelt summary wrong! )
    Birnam wood is come to Dunsinane

  3. #3
    Non-Member
    Join Date
    Oct 2007
    Location
    United Kingdom
    Posts
    622
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That was quick Tommy!!!

    Nice simple answer too

    Thanks


Bookmarks

Posting Permissions

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