Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #18285

Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26)

Message-ID <1388733.rf3QE0b1RE@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-01-28 23:40 +0100
Subject Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26)
Newsgroups comp.lang.javascript
References <51031c8a$0$289$14726298@news.sunsite.dk> <q7VcV3KhTYBRFwQv@invalid.uk.co.demon.merlyn.invalid> <BqidnVGAKqG4xJvMnZ2dnUVZ_vWdnZ2d@westnet.com.au> <XnsA156A595A1093eejj99@194.109.133.133> <Jd2dnRnQztPfcpvMnZ2dnUVZ_sadnZ2d@westnet.com.au>

Show all headers | View raw


Andrew Poulos wrote:

> On 29/01/2013 2:16 AM, Evertjan. wrote:
>> Andrew Poulos wrote on 28 jan 2013 in comp.lang.javascript:
>>> On 28/01/2013 6:49 AM, Dr J R Stockton wrote:
>>>> FAQ server posted:
>>>>> An element can only be accessed after it exists in the document.
>>>> False.  An element cannot be accessed after it exists; it can only be
>>>> accessed while it exists.
>>> And how have you defined "exists". Surely an element "exists" in the
>>> HTML even if the browser has not yet parsed the relevant HTML?
>> HTML is just a string of text, the only elements being character numbers.
> 
> Are saying that when some agent parses some HTML then and only then has
> the document come into existence? Hence an element can't exist until the
> document does?

(For lack of another thread in this newsgroup, I am posting in this one …)

This whole “discussion” is ridiculous.  First of all, you cannot access an 
element at all.  You can access an element *object* that *represents* an 
element in the document tree, and reflects the element's content attributes 
with shorthand properties, using an implementation of a DOM API.  There 
cannot exist such an object in the way that it is accessible by code

1. before the corresponding element has been parsed

2. after the element node has been removed from the document tree, and there
   are no more references to said object stored in properties accessible by
   the code.

It is not exactly news around here that it is only *safe* to access an 
element object for an element in the document when that document has been 
loaded; that is, all its elements have been parsed.

This typically is the case when or after the document's “load” event occurs; 
the former can be handled in a backwards-compatible and – dare I say it? – 
cross-browser way using the “onload” attribute of the “body” element.  Some 
DOM implementations, particularly those that support the HTML5 API, also 
support the more specific “DOMContentLoaded” event for which there is no 
content attribute (yet).

<http://www.w3.org/TR/2012/CR-html5-20121217/syntax.html#the-end>

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

FAQ Topic - Why does my code fail to access an element? (2013-01-26) "FAQ server" <javascript@dotinternet.be> - 2013-01-26 00:00 +0000
  Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-01-27 19:49 +0000
    Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-28 01:32 +0100
      Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Richard Yates <richard@yatesguitar.com> - 2013-01-27 19:16 -0800
        Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-28 11:58 +0100
      Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-01-29 23:12 +0000
        Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Gene Wirchenko <genew@telus.net> - 2013-01-29 16:45 -0800
        Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Andrew Poulos <ap_prog@hotmail.com> - 2013-01-30 14:38 +1100
          Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-30 09:52 +0100
        Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-30 09:31 +0100
    Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Andrew Poulos <ap_prog@hotmail.com> - 2013-01-28 21:55 +1100
      Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-28 16:16 +0100
        Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Andrew Poulos <ap_prog@hotmail.com> - 2013-01-29 08:35 +1100
          Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-28 23:40 +0100
            Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-29 00:21 +0100
              Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-29 00:53 +0100
                Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-29 21:24 +0100
                Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) John G Harris <niam@jghnorth.org.uk.invalid> - 2013-01-30 14:31 +0000
                Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-30 20:22 +0100
                Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) John G Harris <niam@jghnorth.org.uk.invalid> - 2013-01-31 10:55 +0000
                Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-31 22:42 +0100
                Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) John G Harris <niam@jghnorth.org.uk.invalid> - 2013-02-01 10:55 +0000
                Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-02-01 16:03 +0100
                Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-01-30 15:09 +0000
          Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-01-29 00:03 +0100
    Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) John G Harris <niam@jghnorth.org.invalid> - 2013-01-29 10:10 +0000
      Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-01-30 15:14 +0000
        Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) John G Harris <niam@jghnorth.org.uk.invalid> - 2013-01-31 10:50 +0000
          Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-02-01 23:29 +0000
            Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) John G Harris <niam@jghnorth.org.uk.invalid> - 2013-02-02 11:10 +0000
              Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-02-03 19:39 +0000
                Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Christoph Becker <cmbecker69@gmx.de> - 2013-02-04 01:56 +0100
                Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26) Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-02-06 16:08 +0000

csiph-web