473,508 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is the corrent way to get a reference to the body?

I've been doing this to get a reference to the body node of a document,
but I'm sure there must be something simpler than this:

var arrayOfBodyElements = document.getElementsByTagName("body");
var referenceToBodyNode = arrayOfBodyElements[0];
I tried:

var referenceToBodyNode = document.body;

and:

var referenceToBodyNode = window.body;

both of which got me "body undefined".

So what is the right way to get a reference to the body?

Oct 14 '06 #1
1 1220
VK

Jake Barnes wrote:
I tried:
var referenceToBodyNode = document.body;
and:
var referenceToBodyNode = window.body;
both of which got me "body undefined".
So what is the right way to get a reference to the body?
The right way is the first one:
var bodyRef = document.body.

The problem is that this object doesn't exist until onload event is
fired for the window: this is why you were getting undefined.

So in order to get a reference to document.body you have to use
window.onload handler and finish collecting DOM references from there.

Oct 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6172
by: Robert Oschler | last post by:
I have a "child" document that I use for an IFRAME element that I put into several "parent" documents. These "parent" documents therefore contain the IFRAME whose SRC property is set to the...
72
5737
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
10
2251
by: Tony Johansson | last post by:
Hello Experts!! This class template and main works perfectly fine. I have this class template called Handle that has a pointer declared as T* body; As you can see I have a reference counter in...
3
1020
by: Mars | last post by:
I followed the reference about ADT, and wrote something like below.... #include <stdio.h> /* I intend to make this a list */ struct node_s { int x;
4
2506
by: Flip | last post by:
I'm seeing one of my websites giving me an error message on the page after it loads up as "WXBUnit Undefined" What does that mean? The formatting of the site is horrible! I'm not sure what is...
0
1918
by: Kaimar Seljamäe | last post by:
Hi, I have to create a web service client which uses SOAP encoding but does not use "multi-reference" values (see http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383513 item 10). If I...
9
1495
by: killermookie | last post by:
I'm not a javascripter so this is slightly unfamiliar to me. What I'm trying to do is that if someone clicks the radio button for Other, then the text input for other will become enabled. What...
1
4659
by: Michel Couche | last post by:
Hello, I am starting the development of a newsletter The use of the class MailMessage of System.Net.Mail is quite straightforward for usual contact forms but my question here is "How can I...
4
3838
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.