471,857 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,857 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 1245
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Dante | last post: by
7 posts views Thread by Andrew Poulos | last post: by
2 posts views Thread by Scamjunk | last post: by
aboka
reply views Thread by aboka | last post: by

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.