Connecting Tech Pros Worldwide Help | Site Map

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

francescomoi@usa.com
Guest
 
Posts: n/a
#1: Jul 24 '05
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);
---------

but it doesn't work. I get this error
-----------
bodyPoint.insertBefore is not a function
--------------

What am I doing wrong? Thx.

Richard Cornford
Guest
 
Posts: n/a
#2: Jul 24 '05

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


francescomoi@usa.com wrote:[color=blue]
> Hi.
>
> I'm trying to insert some text between <head> and
> <body> but I'm not able.[/color]

Good, because it makes no sense what so ever to place text between the
HEAD element and the BODY element.
[color=blue]
> I try with:
> --------
> bodyPoint = document.getElementsByTagName('body');[/color]

A call to the getElementsByTagName method returns an object implementing
the NodeList interface.
[color=blue]
> var myLink = document.createElement("a");
> myLink.href = "http://www.yahoo.com";
> myLink.innerHTML = "Yahoo";
> bodyPoint.insertBefore(myLink, bodyPoint);
> ---------
>
> but it doesn't work. I get this error
> -----------
> bodyPoint.insertBefore is not a function[/color]

The NodeList interface does not implement an insertBefore method.
[color=blue]
> --------------
>
> What am I doing wrong? Thx.[/color]

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

Richard.


BootNic
Guest
 
Posts: n/a
#3: Jul 24 '05

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


> "francescomoi@usa.com" <francescomoi@usa.com> wrote:[color=blue]
> news:1122231388.080253.305180@f14g2000cwb.googlegr oups.com....
>
> 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);
> ---------
>
> but it doesn't work. I get this error
> -----------
> bodyPoint.insertBefore is not a function
> --------------
>
> What am I doing wrong? Thx.[/color]

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)
}


--
BootNic Sunday, July 24, 2005 4:05 PM

Good communication is as stimulating as black coffee and just as hard to sleep after.
*Anne Morrow Lindbergh*

ASM
Guest
 
Posts: n/a
#4: Jul 24 '05

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


francescomoi@usa.com wrote:[color=blue]
> Hi.
>
> I'm trying to insert some text between <head> and <body> but I'm
> not able.
>
> I try with:
> --------
> bodyPoint = document.getElementsByTagName('body');[/color]

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];
[color=blue]
> var myLink = document.createElement("a");
> myLink.href = "http://www.yahoo.com";
> myLink.innerHTML = "Yahoo";
> bodyPoint.insertBefore(myLink, bodyPoint);
> ---------
>
> but it doesn't work. I get this error
> -----------
> bodyPoint.insertBefore is not a function[/color]

because ? bodyPoint is an array

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

--
Stephane Moriaux et son [moins] vieux Mac
Closed Thread


Similar JavaScript / Ajax / DHTML bytes