Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-23-2006, 08:43 AM   PM User | #1
Jules Manson
New Coder

 
Join Date: Dec 2005
Location: Los Angeles
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Jules Manson is an unknown quantity at this point
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. ;)
.
Jules Manson is offline   Reply With Quote
Old 01-23-2006, 08:55 AM   PM User | #2
Jules Manson
New Coder

 
Join Date: Dec 2005
Location: Los Angeles
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Jules Manson is an unknown quantity at this point
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. ;)
.
Jules Manson is offline   Reply With Quote
Old 01-23-2006, 12:38 PM   PM User | #3
coothead
Senior Coder

 
coothead's Avatar
 
Join Date: Jan 2004
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 1,543
Thanks: 0
Thanked 195 Times in 191 Posts
coothead will become famous soon enough
for anyone interested, Kor's solution can be seen here...

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

coothead
coothead is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:09 AM.


Advertisement
Log in to turn off these ads.