Span with table elements inside table

F

Falc2199

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
 
R

Randy Webb

Falc2199 said:
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.
 
I

Ivo

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top