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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • francescomoi@usa.com

    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.getEle mentsByTagName( 'body');

    var myLink = document.create Element("a");
    myLink.href = "http://www.yahoo.com";
    myLink.innerHTM L = "Yahoo";
    bodyPoint.inser tBefore(myLink, bodyPoint);
    ---------

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

    What am I doing wrong? Thx.

  • Richard Cornford

    #2
    Re: Inserting text between &lt;head&gt; and &lt;body&gt;

    francescomoi@us a.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.getEle mentsByTagName( 'body');[/color]

    A call to the getElementsByTa gName method returns an object implementing
    the NodeList interface.
    [color=blue]
    > var myLink = document.create Element("a");
    > myLink.href = "http://www.yahoo.com";
    > myLink.innerHTM L = "Yahoo";
    > bodyPoint.inser tBefore(myLink, bodyPoint);
    > ---------
    >
    > but it doesn't work. I get this error
    > -----------
    > bodyPoint.inser tBefore 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.


    Comment

    • BootNic

      #3
      Re: Inserting text between &lt;head&gt; and &lt;body&gt;

      > "francescomoi@u sa.com" <francescomoi@u sa.com> wrote:[color=blue]
      > news:1122231388 .080253.305180@ f14g2000cwb.goo glegroups.com.. ..
      >
      > Hi.
      >
      > I'm trying to insert some text between <head> and <body> but I'm
      > not able.
      >
      > I try with:
      > --------
      > bodyPoint = document.getEle mentsByTagName( 'body');
      >
      > var myLink = document.create Element("a");
      > myLink.href = "http://www.yahoo.com";
      > myLink.innerHTM L = "Yahoo";
      > bodyPoint.inser tBefore(myLink, bodyPoint);
      > ---------
      >
      > but it doesn't work. I get this error
      > -----------
      > bodyPoint.inser tBefore is not a function
      > --------------
      >
      > What am I doing wrong? Thx.[/color]

      window.onload=f unction(){
      htm = document.getEle mentsByTagName( 'html')
      myLink = document.create Element("a");
      myLink.href = "http://www.yahoo.com";
      txt = document.create TextNode('Yahoo ')
      myLink.appendCh ild(txt)
      htm[0].insertBefore(m yLink,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*

      Comment

      • ASM

        #4
        Re: DOM: Inserting text between &lt;head&gt; and &lt;body&gt;

        francescomoi@us a.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.getEle mentsByTagName( '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.getEle mentsByTagName( 'body')[0];
        [color=blue]
        > var myLink = document.create Element("a");
        > myLink.href = "http://www.yahoo.com";
        > myLink.innerHTM L = "Yahoo";
        > bodyPoint.inser tBefore(myLink, bodyPoint);
        > ---------
        >
        > but it doesn't work. I get this error
        > -----------
        > bodyPoint.inser tBefore 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

        Comment

        Working...