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

Discussion in 'Javascript' started by francescomoi@usa.com, Jul 24, 2005.

  1. Guest

    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.
     
    , Jul 24, 2005
    #1
    1. Advertising

  2. Re: Inserting text between <head> and <body>

    wrote:
    > 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:
    > --------
    > bodyPoint = document.getElementsByTagName('body');


    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);
    > ---------
    >
    > but it doesn't work. I get this error
    > -----------
    > bodyPoint.insertBefore is not a function


    The NodeList interface does not implement an insertBefore method.

    > --------------
    >
    > What am I doing wrong? Thx.


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

    Richard.
     
    Richard Cornford, Jul 24, 2005
    #2
    1. Advertising

  3. BootNic Guest

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

    > "" <> wrote:
    > news:....
    >
    > 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.


    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*
     
    BootNic, Jul 24, 2005
    #3
  4. ASM Guest

    wrote:
    > Hi.
    >
    > I'm trying to insert some text between <head> and <body> but I'm
    > not able.
    >
    > I try with:
    > --------
    > bodyPoint = document.getElementsByTagName('body');


    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);
    > ---------
    >
    > but it doesn't work. I get this error
    > -----------
    > bodyPoint.insertBefore is not a function


    because ? bodyPoint is an array

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

    --
    Stephane Moriaux et son [moins] vieux Mac
     
    ASM, Jul 24, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian W
    Replies:
    10
    Views:
    823
    Brian W
    Jul 2, 2003
  2. showme

    PHP and ASP.NET go HEAD to HEAD

    showme, Jul 8, 2004, in forum: ASP .Net
    Replies:
    13
    Views:
    784
    Sherif ElMetainy
    Jul 10, 2004
  3. Karl
    Replies:
    0
    Views:
    434
  4. Jiho Han

    Write into <HEAD></HEAD> section?

    Jiho Han, Jan 14, 2004, in forum: ASP .Net Building Controls
    Replies:
    6
    Views:
    264
    Sam Fields
    Jan 16, 2004
  5. Replies:
    5
    Views:
    236
    A. Sinan Unur
    Sep 8, 2005
Loading...

Share This Page