Adding text between child elements in a node

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • clivethebadger
    New Member
    • Feb 2008
    • 12

    Adding text between child elements in a node

    Hi,
    I've got HTML elements created in JavaScript and have appended them to parent node. How do I add some text in between them in the parent node?

    I need to do something like this....

    Code:
    parent.appendChild(child1);
    //add the text " | " in between...
    parent.appendChild(child2);
    So I've got two elements separated by " | ".

    How do I add this text?

    Thanks,
    Jon
  • mrhoo
    Contributor
    • Jun 2006
    • 428

    #2
    Append a text node to the parent after you append child1.

    parent.appendCh ild(document.cr eateTextNode(' | '));

    or if you wait till after you insert the second element
    parent.insertBe fore(document.c reateTextNode(' | '),child2)

    Comment

    Working...