469,936 Members | 2,487 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

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.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
Jul 20 '05 #1
2 41714


fo******@yahoo.co.uk wrote:
<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)

--

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

Jul 20 '05 #2
> 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
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Robi | last post: by
2 posts views Thread by samuel.adam | last post: by
2 posts views Thread by Christina | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.