using document.getElementsByTagName() safely?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian Richardson

    #1

    using document.getElementsByTagName() safely?

    When is the earliest I can use document.getEle mentsByTagName( ) 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
  • DU

    #2
    Re: using document.getEle mentsByTagName( ) safely?

    Ian Richardson wrote:
    [color=blue]
    > When is the earliest I can use document.getEle mentsByTagName( ) 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[/color]

    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

    Comment

    • Jim Ley

      #3
      Re: using document.getEle mentsByTagName( ) safely?

      On Thu, 13 May 2004 01:07:22 -0400, DU <drunclear@hotW IPETHISmail.com >
      wrote:
      [color=blue]
      >Ian Richardson wrote:
      >[color=green]
      >> When is the earliest I can use document.getEle mentsByTagName( ) 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?[/color]
      >
      >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.[/color]

      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.javas cript FAQ - http://jibbering.com/faq/

      Comment

      • Ian Richardson

        #4
        Re: using document.getEle mentsByTagName( ) safely?

        Jim Ley wrote:
        [color=blue]
        > On Thu, 13 May 2004 01:07:22 -0400, DU <drunclear@hotW IPETHISmail.com >
        > wrote:
        >
        >[color=green]
        >>Ian Richardson wrote:
        >>
        >>[color=darkred]
        >>>When is the earliest I can use document.getEle mentsByTagName( ) 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?[/color]
        >>
        >>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.[/color]
        >
        >
        > 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.[/color]

        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

        Comment

        Working...