Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2005
    Location
    Los Angeles
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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')[0];
    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.
    Sincerly,

    Jules

    Don't get left behind. Peel out the behaviour layer from presentation and structure. Throw your DHTML head first into the woodchipper and deprecate it. My mission statement... Unobtrusing the DOM for world peace. ;)
    .

  • #2
    New Coder
    Join Date
    Dec 2005
    Location
    Los Angeles
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nevermind good people with the help of Kor at webdeveloper.com I found a solution.
    Sincerly,

    Jules

    Don't get left behind. Peel out the behaviour layer from presentation and structure. Throw your DHTML head first into the woodchipper and deprecate it. My mission statement... Unobtrusing the DOM for world peace. ;)
    .

  • #3
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,736
    Thanks
    0
    Thanked 241 Times in 236 Posts
    for anyone interested, Kor's solution can be seen here...

    http://www.webdeveloper.com/forum/sh...ad.php?t=92645

    coothead


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •