Dom appendChild, is there a insertChild?

F

foldface

Hi
Given

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

var newText = parent.frames[1].document.createTextNode("some text");
var theBody= parent.frames[1].document.getElementById("theBody");
theBody.appendChild(newText);


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

Thanks

F
 
M

Martin Honnen

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

var newText = parent.frames[1].document.createTextNode("some text");
var theBody= parent.frames[1].document.getElementById("theBody");
theBody.appendChild(newText);


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

document.body.insertBefore(newText, document.body.firstChild)
 
F

foldface

document.body.insertBefore(newText, document.body.firstChild)

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

Thanks anyway
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top