473,324 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

using document.getElementsByTagName() safely?

When is the earliest I can use document.getElementsByTagName() safely -
must it be after the main HTML document has loaded (so I could trigger
it via body onload), or can I use it earlier than this without
generating a javascript error?

I suspect the answer is the former, but I'm just seeking confirmation
before I make some alterations to the code I'm using.

Thanks,

Ian
Jul 23 '05 #1
3 1278
DU
Ian Richardson wrote:
When is the earliest I can use document.getElementsByTagName() safely -
must it be after the main HTML document has loaded (so I could trigger
it via body onload), or can I use it earlier than this without
generating a javascript error?

I suspect the answer is the former, but I'm just seeking confirmation
before I make some alterations to the code I'm using.

Thanks,

Ian


I confirm it's the former. You can not generate/query for a nodelist
regarding the document without first having finished completely loading
that document.

DU
Jul 23 '05 #2
On Thu, 13 May 2004 01:07:22 -0400, DU <dr*******@hotWIPETHISmail.com>
wrote:
Ian Richardson wrote:
When is the earliest I can use document.getElementsByTagName() safely -
must it be after the main HTML document has loaded (so I could trigger
it via body onload), or can I use it earlier than this without
generating a javascript error?


I confirm it's the former. You can not generate/query for a nodelist
regarding the document without first having finished completely loading
that document.


I don't agree with this, and testing shows it's okay, gEBTN works fine
in Opera 7.5 and IE here for me, pretty sure it works elsewhere too.
Obviously only up to the nodes parsed at that point (immediately
before the script) but it works.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 23 '05 #3
Jim Ley wrote:
On Thu, 13 May 2004 01:07:22 -0400, DU <dr*******@hotWIPETHISmail.com>
wrote:

Ian Richardson wrote:

When is the earliest I can use document.getElementsByTagName() safely -
must it be after the main HTML document has loaded (so I could trigger
it via body onload), or can I use it earlier than this without
generating a javascript error?


I confirm it's the former. You can not generate/query for a nodelist
regarding the document without first having finished completely loading
that document.

I don't agree with this, and testing shows it's okay, gEBTN works fine
in Opera 7.5 and IE here for me, pretty sure it works elsewhere too.
Obviously only up to the nodes parsed at that point (immediately
before the script) but it works.


I've found the same, although I've adopted the "trigger via body onload"
approach as I _suspect_ it _may_ be a _safer_ approach...

Thanks,

Ian
Jul 23 '05 #4

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

Similar topics

6
by: 2obvious | last post by:
This is a pipe dream, I realize, but I'm trying to emulate the functionality of the W3C DOM-supported document.getElementsByTagName method under the very nightmarish Netscape 4. Through some...
4
by: Dante | last post by:
Hello. I have a Javascript that gets data from an XML document and displays it through javascript. The problem is that when I do dcfile.getElementsByTagName("subhead").firstChild.nodeName all I...
7
by: Andrew Poulos | last post by:
I'm using the following code to create a small table with one column and two rows. An image goes into the first cell. //create table var t = document.createElement("TABLE"); t.style.position =...
7
by: adam | last post by:
i'm working on a portion of a CMS that allows content-admins to browse a product list, and add individual products into the taxonomy by clicking checkboxes next to categories they might belong in....
6
by: cj | last post by:
How would I check to see if a element is in an xml document. Here's the document: test.xml <?xml version="1.0" encoding="UTF-8"?> <request> <key>5678</key> <type>0200</type>...
2
by: Scamjunk | last post by:
I have been desperately looking for a treeview-type solution for my problem for the past three weeks and have been greatly unsuccessful. I am totally new to the world of XSLT and I *don't know*...
5
by: subbulakshmi | last post by:
hi how to read data from XMLDocument by using Javascript. i got coding from internet. but its not read data. help me its in JavaScript ----------------------- //server return XML...
2
by: davidson1 | last post by:
Hai friends..for menu to use in my website..i found in one website....pl look below website.... http://www.dynamicdrive.com/dynamicindex1/omnislide/index.htm i downloaded 2 files.... ...
0
by: sujata321 | last post by:
Hi, I need to update an XML file using ASP and javascript/vbscript. But this is not working.It is showing the error – ‘document’ is not defined –in the line ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.