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
On Wed, 15 Jun 2005 17:18:14 -0700, RobG <rgqld@iinet.net.auau> wrote:
[color=blue]
> DKM wrote:[color=green]
>> RobG wrote:
>>[color=darkred]
>>> 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:[/color][/color]
> [...][color=green]
>> 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?
>>[/color]
>
> Then I guess you're stuck with innerHTML, but be aware that it is not
> part of the W3C DOM.
>[color=green]
>>[color=darkred]
>>> <input type="button" value="Add 'Hello World'" onclick="
>>> sayHelloWorld();
>>> ">
>>> <div id="pid"></div>
>>>[/color][/color]
>
> <input type="button" value="Add 'Hello World'" onclick="
>
> var s = '<b>Hello World!!!</b>';
> document.getElementById('pid').innerHTML = s;
>
> ">
> <div id="pid"></div>
>
>
>
>
>[/color]
--
Using Opera's revolutionary e-mail client:
http://www.opera.com/mail/