By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,286 Members | 1,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,286 IT Pros & Developers. It's quick & easy.

using document.getElementsByTagName() safely?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.