DOM: Inserting text between <head> and <body>

F

francescomoi

Hi.

I'm trying to insert some text between <head> and <body> but I'm
not able.

I try with:
--------
bodyPoint = document.getElementsByTagName('body');

var myLink = document.createElement("a");
myLink.href = "http://www.yahoo.com";
myLink.innerHTML = "Yahoo";
bodyPoint.insertBefore(myLink, bodyPoint);
 
R

Richard Cornford

Hi.

I'm trying to insert some text between <head> and
<body> but I'm not able.

Good, because it makes no sense what so ever to place text between the
HEAD element and the BODY element.
I try with:

A call to the getElementsByTagName method returns an object implementing
the NodeList interface.
var myLink = document.createElement("a");
myLink.href = "http://www.yahoo.com";
myLink.innerHTML = "Yahoo";
bodyPoint.insertBefore(myLink, bodyPoint);

The NodeList interface does not implement an insertBefore method.

Failing to RTFM, or failing to think about their content.

Richard.
 
B

BootNic

Hi.

I'm trying to insert some text between <head> and <body> but I'm
not able.

I try with:
--------
bodyPoint = document.getElementsByTagName('body');

var myLink = document.createElement("a");
myLink.href = "http://www.yahoo.com";
myLink.innerHTML = "Yahoo";
bodyPoint.insertBefore(myLink, bodyPoint);

window.onload=function(){
htm = document.getElementsByTagName('html')
myLink = document.createElement("a");
myLink.href = "http://www.yahoo.com";
txt = document.createTextNode('Yahoo')
myLink.appendChild(txt)
htm[0].insertBefore(myLink,document.body);
alert(htm[0].innerHTML)
}
 
A

ASM

Hi.

I'm trying to insert some text between <head> and <body> but I'm
not able.

I try with:

not correct : you got the body tree (collection of all body tags)
Hu ? there is only one ?
Does browser know you use a collection instruction to catch one object ?

bodyPoint = document.getElementsByTagName('body')[0];
var myLink = document.createElement("a");
myLink.href = "http://www.yahoo.com";
myLink.innerHTML = "Yahoo";
bodyPoint.insertBefore(myLink, bodyPoint);

because ? bodyPoint is an array

to which one of its elements the browser will address insertion ?
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top