Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 24th, 2005, 07:05 PM
francescomoi@usa.com
Guest
 
Posts: n/a
Default DOM: Inserting text between <head> and <body>

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.


  #2  
Old July 24th, 2005, 07:35 PM
Richard Cornford
Guest
 
Posts: n/a
Default Re: 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.


  #3  
Old July 24th, 2005, 08:15 PM
BootNic
Guest
 
Posts: n/a
Default Re: 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*

  #4  
Old July 24th, 2005, 08:25 PM
ASM
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.