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


Groups > comp.lang.javascript > #12202

Re: How to programmatically display a value

Message-ID <1963616.aqSPkdTlGX@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-02-27 17:40 +0100
Subject Re: How to programmatically display a value
Newsgroups comp.lang.javascript
References <ji9cvn$pqa$1@dont-email.me> <ji9grj$a07$1@dont-email.me> <1403837.V9SEqChMir@PointedEars.de> <4f4b98cd$0$6909$e4fe514c@news2.news.xs4all.nl>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Erwin Moller wrote:

> On 2/25/2012 1:19 PM, Thomas 'PointedEars' Lahn wrote:
>> Cal Who wrote:
>>> I don't know if this is the "best" way to display a numeral but I found
>>> the innerHTML property on the span element and that appears to work OK.
>>
>> You are displaying a numeral, not parsing HTML markup; using innerHTML is
>> overkill, not standardized, and therefore error-prone.  Use the
>> `nodeValue' property of the `firstChild' of the span element object (you
>> should provide it with a child node, say<span>&nbsp;</span>).
> 
> Why did you say using innerHTML is error-prone?
> 
> Are you saying it is error-prone *because* it is not standardized?
> Or it it error-prone for a different reason?

Both.

> I ask because I never encountered any problems using innerHTML for
> simple tasks like displaying a number.

Because it is a simple task and it is only a number string, not markup, 
`innerHTML' is overkill.  It is also proprietary and error-prone.  
Therefore, it is best avoided here.

> What is it are you warning for here?

We really have discussed this ad nauseam here.  To reiterate: The 
`innerHTML' property facilitates only a proprietary de-/serialization of the 
document tree, entirely at the discretion of the implementor.  Among other 
things, this means that you can write to the `innerHTML' property but you 
cannot know if this worked.  There is no exception thrown and reading back 
the property value very likely yields a different string value than the one 
you previously wrote to it.  `innerHTML' breaks with tables, except when you 
generate the whole table with `innerHTML'.  `innerHTML' also (very 
obviously) is not supposed to work in XHTML.  All this is very different 
with the standardized DOM manipulation methods.


PointedEars
-- 
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
  -- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)

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


Thread

How to programmatically display a value " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-24 20:19 -0500
  Re: How to programmatically display a value " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-24 21:25 -0500
    Re: How to programmatically display a value Swifty <steve.j.swift@gmail.com> - 2012-02-25 06:46 +0000
    Re: How to programmatically display a value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-25 13:19 +0100
      Re: How to programmatically display a value Dr J R Stockton <reply1208@merlyn.demon.co.uk> - 2012-02-26 20:38 +0000
      Re: How to programmatically display a value Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-02-27 15:53 +0100
        Re: How to programmatically display a value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-27 17:40 +0100

csiph-web