Creating a DIV with special text

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Csaba2000

    Creating a DIV with special text

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

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

    But the following does not work:
    newText = document.create TextNode(myText );
    newDiv.appendCh ild(newText);

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


    Thanks,
    Csaba Gabor from New York


  • Shawn Milochik

    #2
    Re: Creating a DIV with special text

    Csaba2000 said the following on Sat, 23 Aug 2003 14:27:48 -0400:
    [color=blue]
    > What's the recommended way to add text with entities (e.g. myText =
    > "foo b ar") to a newly created DIV?
    >
    > I might create the DIV like so:
    > newDiv = document.create Element("DIV");
    >
    > But the following does not work:
    > newText = document.create TextNode(myText );
    > newDiv.appendCh ild(newText);
    >
    > The following does work, but is it the recommended way?:
    > newDiv.innerHTM L = myText
    >
    >
    > Thanks,
    > Csaba Gabor from New York[/color]

    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

    Comment

    Working...