D
Danny
A text node is just that, a text node, NOT an ELEMENT node, <b> is an
element node, you've have to
s=document.createElement('b').appenChild(document.createTextNode('STUFF
HERE')); or, as suggested already, use .innerHTML, text nodes is just the
string, no formatting, just text/plain, .innerHTML is a defacto standard
property which does take html as data, works fine, and you do need to
escape reserved chars s.innerHTML='<b> GRASS ISN\'T YELLOW<\/b>';
Danny
element node, you've have to
s=document.createElement('b').appenChild(document.createTextNode('STUFF
HERE')); or, as suggested already, use .innerHTML, text nodes is just the
string, no formatting, just text/plain, .innerHTML is a defacto standard
property which does take html as data, works fine, and you do need to
escape reserved chars s.innerHTML='<b> GRASS ISN\'T YELLOW<\/b>';
Danny
DKM said:[...]RobG said:DKM wrote:
I have an empty tag like <p id="pid"></p> in a xml file. And, I have a
script as foolows:
str = "<b>Hello World!!!</b>";
ele = documeny.getElementById("pid");
ele.appendChild(document.createTextNode(str));
This will create a text node with a value of the literal string
"<b>Hello World!!!</b>".
If you are expecting an HTML <B> element containing the text "Hello
World!!!" then you need to create the B element and put the text
inside
it:
I was doing that from inside a java applet, but due to buggy nature of
LiveConenct, I am creating a html formated string in the java applet
and passing it to javascript. That has been working robustly without
any crash. Now, the problem is to insert that html formatted string
into the document.
Any idea as to how one can dynamically insert a long and compleex html
formated string into the document?
Then I guess you're stuck with innerHTML, but be aware that it is not
part of the W3C DOM.
<input type="button" value="Add 'Hello World'" onclick="
var s = '<b>Hello World!!!</b>';
document.getElementById('pid').innerHTML = s;
">
<div id="pid"></div>