Dom appendChild, is there a insertChild?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • foldface@yahoo.co.uk

    #1

    Dom appendChild, is there a insertChild?

    Hi
    Given

    <body id="theBody">
    <p> 1
    <p> 2
    <p> 3
    <p> 4
    <p> 5
    <p> 6
    </body>

    var newText = parent.frames[1].document.creat eTextNode("some text");
    var theBody= parent.frames[1].document.getEl ementById("theB ody");
    theBody.appendC hild(newText);


    This will insert an element after the last <p>, can I insert one
    after the body but before the first <p>?

    Thanks

    F
  • Martin Honnen

    #2
    Re: Dom appendChild, is there a insertChild?



    foldface@yahoo. co.uk wrote:
    [color=blue]
    > <body id="theBody">
    > <p> 1
    > <p> 2
    > <p> 3
    > <p> 4
    > <p> 5
    > <p> 6
    > </body>
    >
    > var newText = parent.frames[1].document.creat eTextNode("some text");
    > var theBody= parent.frames[1].document.getEl ementById("theB ody");
    > theBody.appendC hild(newText);
    >
    >
    > This will insert an element after the last <p>, can I insert one
    > after the body but before the first <p>?[/color]

    document.body.i nsertBefore(new Text, document.body.f irstChild)

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • foldface@yahoo.co.uk

      #3
      Re: Dom appendChild, is there a insertChild?

      > document.body.i nsertBefore(new Text, document.body.f irstChild)

      sorry, spotted the problem 10 minutes after posting but as I post via
      google couldn't answer the post myself, its getElementsByTa gName,
      missed the 's' off. Did try insertBefore but it wouldn't work due to that
      error!

      Thanks anyway

      Comment

      Working...