[Javascript] how to refer to (x)html elements

David Lovering dlovering at gazos.com
Thu Nov 13 11:45:48 CST 2003


A postscript to my last note --

I was aware of the fact that getElementsByTagName returned an array, whereas
getElementById returned a single object.  If my message inferred otherwise,
it was no doubt due to the alacrity with which I popped it off (and the
corresponding lack of editorial review).   On that score, Mea Culpa.

Hassan is correct on that point, and although I don't believe my earlier
note explicitly erred, it is important to make the distinction.

On the other matter, CSS was designed to provide * reproducible * style
elements, i.e; ones which are intended to be applied to more than one
object.  Having a style element which can properly be attached to one and
only one object sort of voids the mission directive, don't you think?  It is
unfortunate that they chose "ID" as the attribute to communicate the style
element to the object.  On that issue I believe Hassan and I are in complete
agreement.  [While "CLASS" does demonstrably work in a similar capacity on
some browsers, the lack of uniformity is still problematic].

Thanks again for keeping me honest.

-- Dave Lovering


----- Original Message ----- 
From: "Hassan Schroeder" <hassan at webtuitive.com>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Thursday, November 13, 2003 7:38 AM
Subject: Re: [Javascript] how to refer to (x)html elements


> David Lovering wrote:
>
> > The real problem with "id" in HTML (and correspondingly in JavaScript)
is
> > that it tries to do too many things.
>
> <non-standards-compliant example removed/>
>
> Nonsense. ID does one thing -- it identifies a *single* element.
>
> And if you ignore the standard, and it *seems* to work -- so what?
> You ran with scissors and didn't poke your eye out, you went 65mph
> in a 35 zone and didn't get a ticket. So what?
>
> The standard is unambiguous. ID must be unique within a document.
>
> As Roger points out, getElement*s*ByTagName, plural, returns an
> array; getElementById, singular, does not. A quick search turns up
> this good snippet on the DOM:
>
> /* source: <http://xml.apache.org/xalan-j/apidocs/index.html> */
>
>    org.w3c.dom
>      Interface Document  extends org.w3c.dom.Node
>
>   getElementById
>
>      public Element getElementById(java.lang.String elementId)
>
>    Returns the Element whose ID is given by elementId. If no such
>    element exists, returns null. Behavior is not defined if more
>    than one element has this ID. ...
>
>    Parameters:
>      elementId - The unique id value for an element.
>    Returns:
>      The matching element.
>    Since:
>      DOM Level 2
>
> "Behavior is not defined" kinda sums it up, eh? :-)
>
> FWIW!
> -- 
> Hassan Schroeder ----------------------------- hassan at webtuitive.com
> Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com
>
>                            dream.  code.
>
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>





More information about the Javascript mailing list