1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

My getElementById('pc') and getElementsByTagName('BODY') give errors.

Discussion in 'JavaScript' started by Jules Manson, Jan 22, 2006.

?

How would you grade my request for help?

  1. Grade A - Concise, Complete, and Courteous

    0 vote(s)
    0.0%
  2. Grade B - Lacking one from Grade A

    0 vote(s)
    0.0%
  3. Grade C - Lacking two from Grade A

    0 vote(s)
    0.0%
  4. Grade D - Lacking three from Grade A

    0 vote(s)
    0.0%
  1. #1
    For the most part I do know how to use these two functions as I have used them before. The problem is that when I point to the body tag it creates errors. I am using Windows XP Home edition and this bit of script produces errors on MSIE 6.0 and the script is completely ignored on Firefox 1.5 and Opera 8.51. I prefer to point to the body tag because it is the easiest and most convenient place to navigate through the DOM tree especially since the elements that I intend to create will become the first child of my body tag.

    The error I get when using getElementById on MSIE is "Error: docBody is null or not an object." The error I get when using getElementsByTagName on MSIE is "Error: Object doesn't support this property or method."

    The ultimate goal of my script is to create the following HTML as a first child of the body tag. However for now I will happily settle on why I am getting errors.

    <DIV class="topanchor"><A name="top" class="ghost">top</A></DIV>

    The complete HTML is:

    <HTML>
    <HEAD>
    <TITLE>Request For Help - PageBuilder</TITLE>
    <SCRIPT>
    var docBody = document.getElementById('pc');
    // var docBody = document.getElementsByTagName('BODY');
    firstDiv = docBody.appendChild(document.createElement('DIV'));
    firstDiv.className = 'topanchor';
    topAnchor = firstDiv.appendChild(document.createElement('A'));
    topAnchor.className = 'ghost';
    topAnchor.Name = 'top';
    topAnchor.appendChild(document.createTextNode('top'));
    </SCRIPT>
    </HEAD>
    <BODY ID="pc">
    </BODY>
    </HTML>

    I really do appreciate help offered as this is evident in the countless hours that I have spent in instant messaging helping others with Windows anamolies which is something that I am very knowledgable in. Please test your solution before providing one. If you cannot provide an adequate answer to my query please do not respond to this posting. Useless responses tend to make postings long, difficult to follow, and old. Thank you for your cooperation.
     
    Jules Manson, Jan 22, 2006 IP
  2. Jules Manson

    Jules Manson Peon

    Messages:
    20
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Nevermind good people with the help of Kor at webdeveloper.com I found a solution. :)
     
    Jules Manson, Jan 23, 2006 IP