Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #16539
| From | Matt McDonald <matt@fortybelow.ca> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: firstChild Problem |
| Date | 2012-10-10 13:56 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <k54cu6$cgj$1@dont-email.me> (permalink) |
| References | <adlp3qFhpnlU1@mid.individual.net> |
On 10/10/12 13:20, Mel Smith wrote: > // Here is the line that results in the error: > > srchtxt.firstChild.nodeValue = "Searching ..."; As your HTML mark-up illustrates, there is no `Text` node with which one could work. `<span></span>` will create an `HTMLSpanElement` in the document tree with no child nodes. > // Yet if I intentionally place a 'searching ...' string > // in the<span> on the original page, it works correctly, and if I then > // set the nodeValue later to "" (i.e., empty string), and re-enter my > function, > // there is no error ? Yes, as the text added between the start and end tags denotes a `Text` node that will be created as a child node of the `HTMLSpanElement`. Thus, it is available to be scripted. Once the node has been created in the document tree, it needs to be removed in order to discard it--and even then, references inside of scripts can still access it, so the references need to be cleared. Emptying its `nodeValue` property will not delete it: the node still exists in the document tree. Using intial text as you have done is a good idea, as it provides an initial state for the client before any scripting is performed. If JavaScript is disabled or the corresponding script does not execute, the initial state will be presented. -- `The theologian Meric Casaubon argued--in his 1668 book, *Of Credulity and Incredulity*--that witches must exist because, after all, everyone believes in them. Anything that a large number of people believe must be true'--Carl Sagan--*The Demon-Haunted World*.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
firstChild Problem "Mel Smith" <med_cutout_syntel@aol.com> - 2012-10-10 11:20 -0600
Re: firstChild Problem -- Correction "Mel Smith" <med_cutout_syntel@aol.com> - 2012-10-10 11:35 -0600
Re: firstChild Problem -- Correction "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-10-10 20:42 +0300
Re: firstChild Problem Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-10 17:40 +0000
Re: firstChild Problem Matt McDonald <matt@fortybelow.ca> - 2012-10-10 13:56 -0400
Re: firstChild Problem "Mel Smith" <med_cutout_syntel@aol.com> - 2012-10-10 12:13 -0600
csiph-web