Span with table elements inside table

Discussion in 'Javascript' started by Falc2199, Jun 8, 2004.

  1. Falc2199

    Falc2199 Guest

    i all,
    I have an HTML table within which I have a span. When the user
    clicks a button I want to update the contents of this span with form
    elements table elements (TR,TD).

    The problem is that if I do not wrap the span tag inside a TR
    and TD, it is not properly placed in the table and the update does not
    work at all. However if I do place the span inside a TR and TD, the TR
    and TD which was supposed to go into the span is not becoming properly
    aligned because now I have nested TR and TDs.

    Anyone have any thougts, here is some sample code....

    function repeatQuestion(divHtml, divId) {


    var elem = document.getElementById(divId);
    elem.innerHTML = divHtml; // divHtml contains TD and TRs

    }

    <table>

    <span id="divId"></span> // this does not work
    <tr><td><span id="divId"></span></td></tr> // this works but format
    messed up

    <input type=button onClick=repeatQuestion(divHtml,divId)>

    </table>

    Thanks in advance,
    Jehan
     
    Falc2199, Jun 8, 2004
    #1
    1. Advertising

  2. Falc2199

    Randy Webb Guest

    Falc2199 wrote:
    > i all,
    > I have an HTML table within which I have a span. When the user
    > clicks a button I want to update the contents of this span with form
    > elements table elements (TR,TD).
    >
    > The problem is that if I do not wrap the span tag inside a TR
    > and TD, it is not properly placed in the table and the update does not
    > work at all. However if I do place the span inside a TR and TD, the TR
    > and TD which was supposed to go into the span is not becoming properly
    > aligned because now I have nested TR and TDs.
    >
    > Anyone have any thougts, here is some sample code....
    >
    > function repeatQuestion(divHtml, divId) {
    >
    >
    > var elem = document.getElementById(divId);
    > elem.innerHTML = divHtml; // divHtml contains TD and TRs
    >
    > }
    >
    > <table>
    >
    > <span id="divId"></span> // this does not work
    > <tr><td><span id="divId"></span></td></tr> // this works but format
    > messed up
    >
    > <input type=button onClick=repeatQuestion(divHtml,divId)>
    >
    > </table>


    Instead of divHtml containing "TD and TR's", have it contain TABLE, TR
    and TD tags. Then, you are not inserting fragments of tables, but entire
    tables.

    Or, use appendChild to add to an existing table.


    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq/
     
    Randy Webb, Jun 8, 2004
    #2
    1. Advertising

  3. Falc2199

    Ivo Guest

    "Falc2199" wrote
    > I have an HTML table within which I have a span. When the user
    > clicks a button I want to update the contents of this span with form
    > elements table elements (TR,TD).
    >
    > The problem is that if I do not wrap the span tag inside a TR
    > and TD, it is not properly placed in the table and the update does not
    > work at all. However if I do place the span inside a TR and TD, the TR
    > and TD which was supposed to go into the span is not becoming properly
    > aligned because now I have nested TR and TDs.
    >


    Why do you need that span? Replace the (contents of) the TR's and TD's
    directly.
    The table and its children are very useful elements, but of course you need
    to keep them properly nested. That means a TABLE can only contain TR, TBODY,
    THEAD and TFOOT elements. A TR can only contain TH and TD elements, but
    they can contain all sorts of other elements.
    If that is all right, you can easily make use of the rows and cells
    collections to access and manipulate whatever you like, even without the
    need for unique ID's on each element.
    Ivo
     
    Ivo, Jun 8, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fulio Open

    Can span include span?

    Fulio Open, Jun 26, 2009, in forum: HTML
    Replies:
    5
    Views:
    552
    dorayme
    Jun 26, 2009
  2. Stéphane Klein
    Replies:
    2
    Views:
    1,768
    John Nagle
    Mar 30, 2010
  3. Stefan Behnel
    Replies:
    0
    Views:
    489
    Stefan Behnel
    Mar 29, 2010
  4. Dan Bishop

    DataGrid (body only) contained in <span>...</span> tags

    Dan Bishop, Jun 7, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    280
    Kilic Beg
    Jun 7, 2004
  5. Wang, Jay
    Replies:
    5
    Views:
    477
    Wang, Jay
    May 25, 2004
Loading...

Share This Page