innerHTML

A

Alejandro Narancio

Hi for everyone. First of all i'm trying to explain waht i want to do.
I need to insert some code (for example the beggining of a table)
before the code inside of a div, and some other code (for exaple the
end of a table) after the code inside of a div. Here is an example:

Actual code:

<body>
<div id="idDIV">
<table>
<tr>
<td>Some text</td>
</tr>
</table>
</div>
</body>


I want to make the code above like this:


<body>
<div id="idDIV">
<table>
<tr>
<td>
<table>
<tr>
<td>Some text</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>

I'm trying to do this with this code:
var code = '<table><tr><td>'+document.all.idDIV.innerHTML+'</td></tr></table>';
document.all.idDIV.innerHTML = "";
document.all.idDIV.innerHTML = code;

This code work if inside the Div there isn't a table, if inside the
div exists a table an error ocur: "Untermiated string"

Anybody know hoy can i fix this?

Thanks,

Alejandro
 
T

Thomas 'PointedEars' Lahn

Alejandro said:
I'm trying to do this with this code:
var code = '<table><tr><td>'+document.all.idDIV.innerHTML+'</td></tr></table>';
document.all.idDIV.innerHTML = "";
document.all.idDIV.innerHTML = code;

This code work if inside the Div there isn't a table, if inside the
div exists a table an error ocur: "Untermiated string"
Anybody know hoy can i fix this?

Try to replace "</" with "<\/". ETAGOs must not occur within CDATA,
otherwise the element is considered closed and the element's content
is incomplete code (which would explain the error message).

BTW, "document.all" is (currently) IE-only (some UAs like Opera emulate
parts of its object model, though) and both the former and "innerHTML"
are proprietary. Use document.getElementById("idDIV").textContent
(DOM Level 3) or its DOM Level 2+ node manipulation methods instead.


PointedEars
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top