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


Groups > comp.lang.javascript > #18310

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

From Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Newsgroups comp.lang.javascript
Subject Re: FAQ Topic - Why does my code fail to access an element? (2013-01-26)
Date 2013-02-01 23:29 +0000
Organization Home
Message-ID <XBOzrxTH$EDRFwES@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <51031c8a$0$289$14726298@news.sunsite.dk> <q7VcV3KhTYBRFwQv@invalid.uk.co.demon.merlyn.invalid> <6HBzbHF9$5BRFwBz@J.A830F0FF37FB96852AD08924D9443D28E23ED5CD> <yjcaDVEIjTCRFw64@invalid.uk.co.demon.merlyn.invalid> <jrYmgXE+xkCRFwIa@J.A830F0FF37FB96852AD08924D9443D28E23ED5CD>

Show all headers | View raw


In comp.lang.javascript message <jrYmgXE+xkCRFwIa@J.A830F0FF37FB96852AD0
8924D9443D28E23ED5CD>, Thu, 31 Jan 2013 10:50:38, John G Harris
<niam@jghnorth.org.uk.invalid> posted:

>In message <yjcaDVEIjTCRFw64@invalid.uk.co.demon.merlyn.invalid>, Dr J
>R Stockton wrote:
>
>  <snip>
>>"An element can be accessed only while it exists in a document."
>
>Then this has to be followed by a reminder that the element object
>might not exist yet when the failing code is executed. That's the whole
>point of the FAQ entry.

That should be obvious, but can be covered by something like "... in a
document, as part of the DOM tree.".  Except, of course, for the fact
that it would then be incorrect.

        "An element can be accessed only while it exists."

The "in a document" is probably intended to mean "in the DOM tree"
(which is sufficient but not necessary), and might by the intended
readership be taken as meaning "in the HTML" or "in
document.body.innerHTML" or similar.

 "An element can be accessed only while it and a reference to it exist."

>The FAQ entry is not about what happens when an element object is
>removed from the DOM tree.


That was the original intention.  But the original intention is
irrelevant; it is the Subject which defines the question.

Imagine, for example

<div ID=A>xxx<span ID=B>yyy</span>zzz</span>

<script>
  RA = document.getElementById("A")
  RB = document.getElementById("B")
</script>

It is easy to write to A and to B.

After   RA.innerHTML = "---"   it should be clear enough that B cannot
be visibly written to, as it no longer visibly exists.  But a reference
to it exists, so it should not be garbage-collected, and it could be
inserted elsewhere in the DOM tree to show "yyy".

Then what about  RA.innerText = ""  which will visibly blank the DIV?
For an ordinarily naive coder, it would not be unreasonable to expect
the SPAN to still be in the DIV - and it would also not be unreasonable
to expect the SPAN to not still be in the DIV.  Neither is unreasonable;
one must be right, and one wrong.  There is still a reference to B.


The FAQ should first say something about elements, then references to
elements, then say how a DOM tree for display is grown, and can be
grafted and pruned.  It is then only necessary to say something about
the displayed properties of elements, and about the inner* methods.


See in <http://www.merlyn.demon.co.uk/js-faq-u.htm>, which does
something like that.

-- 
 (c) John Stockton, Surrey, UK.  ¬@merlyn.demon.co.uk   Turnpike v6.05   MIME.
   Web  <http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
 Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
 Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

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