PDA

View Full Version : No HTML in document.createTextNode


winlineau
07-16-2002, 05:01 AM
my script:

<div id=thediv></div>
<script>
doit = thediv.appendChild
thediv.innerHTML = "<table border='1' width='57%' height='300'><tr><td width='100%' height='300' valign='top'>";
thediv.appendChild(document.createTextNode("<center><h1>WINLINE Networks:</h1></center><hr><p align='center'><font size='5'>A report on"));
thediv.appendChild(document.createTextNode("how and what is happening</font></p></td></tr></table>"));
</script>


Only shows text?? :eek: :eek: :eek: :eek: :eek: :eek: :eek:

Please Help.
Thanks in advance

Tim

jkd
07-16-2002, 06:00 AM
Notice the "Text" part of createTextNode? :)

In DOM, Text is defined as character data, and is not run through an HTML/XML parser.

You have used a combination of innerHTML with createTextNode though - if you are willing to use innerHTML, stick with it.

If you must use DOM methods, you'd have to wait until browsers support the DOM3 Load and Save interface, where you would generate a document from a given string of XML via:

var doc = document.implementation.createDocument('','',null);
doc.loadXML('<tag>some xml</tag>');

Not even Gecko supports the working draft of this DOM3 interface, though it offers its own proprietary alternatives via the DOMParser interface.

To sum it up, stick with innerHTML for a while ;).