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


Groups > comp.lang.javascript > #21658

Re: prob with js...

Message-ID <4035931.IXUBZ7Uc5o@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-10-19 23:45 +0200
Subject Re: prob with js...
Newsgroups comp.lang.javascript
References <l3u1fg$lr7$1@shakotay.alphanet.ch> <0cc5ab2c-9864-4ee8-8306-1d5eaf1e0849@googlegroups.com>

Show all headers | View raw


Danny wrote:

> To Une Bévue

Will you *please* learn to quote?
 
> this one is the case why using innerHTML property is not very reliable for
> READS, only for WRITES, that is, if you inject or ADD the elements to the
> document by using .innerHTML, the WRITE, that is, the ADDITION goes fine,
> but if you try to read any of the elements, like retriving by using the ID
> or even crawling the document tree to it, won't work very well.

Nonsense.
 
> for instances in which you need to READ elements or access elements added
> to the document, do not use the .innerHTML property, instead use the DOM
> methods like .createElement() and .appendChild() and .createTextNode(). 

Nonsense.  The issue with the “innerHTML” is not unreliable read access; it 
is mostly proprietary subtree serialization.  But that has nothing to do 
with the fact that you can add elements with “+=”; it is just inefficient 
because previous siblings need to be serialized.

> Long as the DOM methods may be, and often maybe even redundantly worded,
> they're very reliable when accessing or adding elements to the document.

Very likely the issue here is the common one that the element with ID 
“growlnotifications” has not been parsed yet when

  this.growlnotifications = document.getElementById('growlnotifications');

is executed.  As a result, this.growlnotifications is assigned “null”, and
the assignment in

  this.setText = function (text) {
    this.growlnotifications.innerHTML = text;
  };

fails with something like

|> (null).answer = "42";
| TypeError: Cannot set property 'answer' of null

Therefore, your suggestion will not work.

  this.setText = function (text) {
    document.getElementById('growlnotifications').innerHTML=text;
  };

works because the element object reference is not retrieved before the 
setText() method is called, after the element has been parsed.  The solution 
is not to call the wrapper constructor before the element has been parsed; 
it should be called in the “load” event listener for the “body” element 
instead.

-- 
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

prob with js... Une Bévue <unbewusst.sein@fai.invalid> - 2013-10-19 15:29 +0200
  Re: prob with js... Danny <dann90038@gmail.com> - 2013-10-19 13:02 -0700
    Re: prob with js... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-19 23:45 +0200
      Re: prob with js... Une Bévue <unbewusst.sein@fai.invalid> - 2013-10-20 06:57 +0200
        Re: prob with js... JJ <duh@nah.meh> - 2013-10-20 17:41 +0700
          Re: prob with js... Une Bévue <unbewusst.sein@fai.invalid> - 2013-10-21 08:50 +0200
        Re: prob with js... dhtml <dhtmlkitchen@gmail.com> - 2013-10-20 05:25 -0700
          Re: prob with js... Une Bévue <unbewusst.sein@fai.invalid> - 2013-10-21 08:52 +0200

csiph-web