Creating a DIV with special text

C

Csaba2000

What's the recommended way to add text with entities
(e.g. myText = "foo bar") to a newly created DIV?

I might create the DIV like so:
newDiv = document.createElement("DIV");

But the following does not work:
newText = document.createTextNode(myText);
newDiv.appendChild(newText);

The following does work, but is it the recommended way?:
newDiv.innerHTML = myText


Thanks,
Csaba Gabor from New York
 
S

Shawn Milochik

Csaba2000 said the following on Sat, 23 Aug 2003 14:27:48 -0400:
What's the recommended way to add text with entities (e.g. myText =
"foo bar") to a newly created DIV?

I might create the DIV like so:
newDiv = document.createElement("DIV");

But the following does not work:
newText = document.createTextNode(myText);
newDiv.appendChild(newText);

The following does work, but is it the recommended way?:
newDiv.innerHTML = myText


Thanks,
Csaba Gabor from New York

I'm not sure about doing it in a <DIV>, but you can definitely
do it in a <SPAN> using the .innerHTML property. Of course, you
can then place a <SPAN> in your <DIV>, and change the content of the
<SPAN>.

Shawn
 

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
474,079
Messages
2,570,575
Members
47,207
Latest member
HelenaCani

Latest Threads

Top