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


Groups > comp.lang.javascript > #16266

Re: document.elementname vs document.getElementById("id")

Message-ID <1835562.mW7zK3R6x3@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-09-30 12:22 +0200
Subject Re: document.elementname vs document.getElementById("id")
Newsgroups comp.lang.javascript
References <k47drn$q7j$1@dont-email.me> <k48a8p$he5$1@speranza.aioe.org>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


J.R. wrote:

> On 29/09/2012 15:15, Denis McMahon wrote:
>> I'm arguing to replace using document.formname to identify forms with
>> assigning an id to the forms involved and using document.getElementById
>> ("formid").*, but the best arguments I can think of at the moment (more
>> robust to future changes, better compatibility with developing standards,
>> more maintainable) are butting up against "don't fix it until it needs
>> fixing", whereas I prefer to prevent future breakage, rather than react
>> to it.
> 
> document.formname is okay with HTML 4.

No, it is not.  W3C DOM Level 2 HTML makes it clear that HTML 4(.01) 
documents are to be scripted using W3C DOM Level 2 HTML.  In that sense, 
Netscape's document.formname "is HTML 3.2 and before", as it predates HTML 
4.  Of course, you are confusing markup language and DOM API here.

> You may use the W3C Markup Validation Service to check if an element
> should have an ID.

That is beside the point.  All HTML elements can have an ID; `id' is one of 
the general attributes.  The W3C Markup Validation Service does not check 
ECMAScript-based source code for validity or plausibility.
 
>> I'm pretty certain that using document.getElementById("id") is better
>> than using document.elementname, but at the moment I'm having trouble
>> pointing to any sort of authoritative reference for this.
> 
> I recall MSIE used to pollute the global namespace with elements' names
> or IDs, that is, we could get a reference to an element using
> document.elementname or document.elementID. See
> <http://webbugtrack.blogspot.com.br/2007/09/bug-162-global-namespace-
pollution-in.html>
> 
> The W3C standards compliant browsers use document.getElementById("ID")
> which is DOM level 1 (1998).

DOM Level 1 has been obsoleted by DOM Level 2 more than a decade ago.

> Interestingly, Firefox still allows references in the old way
> (document.elementID or formName.elementName) when a page is rendered in
> "quirks mode".

If you had read my posting before replying you would know why.

>> [1] It was document.all.formname which was breaking, a very senior coder
>> (but not actually a web / js coder) "fixed" it by changing
>> document.all.formname to document.formname, but I think the fix is almost
>> as prone to future breakage as the original code was, and would prefer to
>> see document.getElementById("formid") used instead, with approriate IDs
>> allocated to forms.
> 
> Yes, this sort of "fix" is error prone.

So much, so good.

> But a form's ID is not required in HTML 4 - only XHTML pages should
> require IDs:

Utter nonsense.

> <http://www.w3.org/TR/xhtml1/diffs.html>

Nothing there supports your argument.  What is stated there instead is that 
the `id' attribute is of *type* ID in XHTML 1.0, as opposed to HTML 4.01 
where it is of type NAME, because XML requires that there be only one 
attribute with type ID on an element type.  As a result, anchors must adapt.  
But of course XHTML documents may have `name' attributes (of type CDATA) as 
well.


PointedEars
-- 
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
  -- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>

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


Thread

document.elementname vs document.getElementById("id") Denis McMahon <denismfmcmahon@gmail.com> - 2012-09-29 18:15 +0000
  Re: document.elementname vs document.getElementById("id") Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-29 22:17 +0200
  Re: document.elementname vs document.getElementById("id") dann90038@gmail.com - 2012-09-29 16:21 -0700
  Re: document.elementname vs document.getElementById("id") "J.R." <groups_jr-1@yahoo.com.br> - 2012-09-29 23:20 -0300
    Re: document.elementname vs document.getElementById("id") "J.R." <groups_jr-1@yahoo.com.br> - 2012-09-29 19:53 -0700
    Re: document.elementname vs document.getElementById("id") "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-09-30 11:02 +0300
      Re: document.elementname vs document.getElementById("id") Denis McMahon <denismfmcmahon@gmail.com> - 2012-09-30 13:10 +0000
      Re: document.elementname vs document.getElementById("id") Denis McMahon <denismfmcmahon@gmail.com> - 2012-09-30 13:14 +0000
        Re: document.elementname vs document.getElementById("id") "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-09-30 17:20 +0300
          Re: document.elementname vs document.getElementById("id") Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-09-30 21:09 +0200
            Re: document.elementname vs document.getElementById("id") "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-09-30 22:28 +0300
              Re: document.elementname vs document.getElementById("id") Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-09-30 21:53 +0200
            Re: document.elementname vs document.getElementById("id") Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-30 21:53 +0200
          Re: document.elementname vs document.getElementById("id") Denis McMahon <denismfmcmahon@gmail.com> - 2012-09-30 22:07 +0000
            Re: document.elementname vs document.getElementById("id") "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-10-01 06:23 +0300
              Re: document.elementname vs document.getElementById("id") Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-01 08:11 +0000
                Re: document.elementname vs document.getElementById("id") Stefan Weiss <krewecherl@gmail.com> - 2012-10-01 11:25 +0200
      Re: document.elementname vs document.getElementById("id") "J.R." <groups_jr-1@yahoo.com.br> - 2012-09-30 15:10 -0300
        Re: document.elementname vs document.getElementById("id") Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-30 20:43 +0200
    Re: document.elementname vs document.getElementById("id") Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-30 12:22 +0200
      Re: document.elementname vs document.getElementById("id") "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-09-30 13:44 +0300
        Re: document.elementname vs document.getElementById("id") Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-30 13:46 +0200
  Re: document.elementname vs document.getElementById("id") Dr J R Stockton <reply1239@merlyn.demon.co.uk.invalid> - 2012-09-30 20:10 +0100

csiph-web