469,328 Members | 1,271 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

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 1209
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.